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

Output buffer gets cleared after legacy call

    XMLWordPrintable

    Details

      Description

      Using public API, if we perform a legacy call the output buffer gets cleared for some reason.
      This doesn't seems the correct behavior.


      Steps to reproduce:

      Create a bundle, and add a command to it, containing the following code:

              // Generate output buffer
              ob_start();
              echo "test\n";
              $levelBefore = ob_get_level();
      
              // This legacy call will clean the ob and discard our output of 'test'
              $closure = $this->getContainer()->get('ezpublish_legacy.kernel');
              $legacyKernel = $closure();
              $legacyKernel->runCallback(
                  function () {
                  },
                  false,
                  false
              );
      
              // Dump differences
              $levelAfter = ob_get_level();
              $content = ob_get_clean();
              printf("ob_get_level() before legacy call: %d\n", $levelBefore);
              printf("ob_get_level() after legacy call: %d\n", $levelAfter);
              printf("Content: %s\n", $content);
      

      The content of $levelAfter should be the same as $levelBefore, but it isn't, because the output buffer has been flushed.

      The same can be tested with ob_get_contents():

              // Generate output buffer
              ob_start();
              echo "test\n";
              $bufferBefore = ob_get_contents();
      
              // This legacy call will clean the ob and discard our output of 'test'
              $closure = $this->getContainer()->get('ezpublish_legacy.kernel');
              $legacyKernel = $closure();
              $legacyKernel->runCallback(
                  function () {
                  },
                  false,
                  false
              );
      
              // Dump differences
              $bufferAfter = ob_get_contents();
              $content = ob_get_clean();
              var_dump($bufferBefore);
              var_dump($bufferAfter);
              printf("Content: %s\n", $content);
      

      Which will output:

      string(5) "test
      "
      bool(false)
      Content: 
      

      bool(false) will be returned when dumping $bufferAfter because the output buffer has been flushed after the legacy call.

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            ricardo.correia-obsolete@ez.no Ricardo Correia (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 day, 2 hours, 40 minutes
                1d 2h 40m