Uploaded image for project: 'eZ Publish / Platform'
  1. eZ Publish / Platform
  2. EZP-28886

Method eZ\Publish\Core\FieldType\Page\Value::__toString() does not always return String

    XMLWordPrintable

Details

    Description

      Currently, the method eZ\Publish\Core\FieldType\Page\Value::__toString() does not always return String. It returns null if the page layout equals null. This can cause further issues because PHP throws an error if magic method __toString() returns something different then String.
      Most of the other Value classes are casting the value returned from __toString() to String, so this is what most probably should also be done in this case.

      Steps to reproduce

      1. Set up new eZ Platform installation.
      2. Create a new Symfony Command with the following code:
            <?php
        
        namespace AppBundle\Command;
        
        use eZ\Publish\Core\FieldType\Page\Parts\Page;
        use eZ\Publish\Core\FieldType\Page\Value;
        use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
        use Symfony\Component\Console\Input\InputInterface;
        use Symfony\Component\Console\Output\OutputInterface;
        
        class TestCommand extends ContainerAwareCommand
        {
            protected function configure()
            {
                $this
                    ->setName('app:test_command');
            }
        
            protected function execute(InputInterface $input, OutputInterface $output)
            {
                $page = new Page();
                $pageValue = new Value($page);
        
                echo $pageValue;
            }
        }
        
      3. Run the created command by executing the following:
        php app/console app:test_command
        

        You will be presented with the following error:

         [Symfony\Component\Debug\Exception\ContextErrorException]
          Catchable Fatal Error: Method eZ\Publish\Core\FieldType\Page\Value::__toString() must return a string value
        

        The expected behaviour is that the code runs without any error.

      Attachments

        Activity

          People

            Unassigned Unassigned
            jacek.foremski-obsolete@ez.no Jacek Foremski (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: