|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #65004 SoapServer::handle() should return instead of print
Submitted: 2013-06-10 12:42 UTC Modified: -
Avg. Score:4.4 ± 0.7
Reproduced:6 of 6 (100.0%)
Same Version:4 (66.7%)
Same OS:5 (83.3%)
From: kjarli at gmail dot com Assigned:
Status: Open Package: SOAP related
PHP Version: 5.3.26 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: kjarli at gmail dot com
New email:
PHP Version: OS:


 [2013-06-10 12:42 UTC] kjarli at gmail dot com
Case: I'm using a framework with MVC, symfony2. I'm using SOAP for 1 part of the 
system to receive notifications by an external party. Using SoapServer::handle() 
requires me to hack/cheat on the MVC pattern. 

Say I want to use the normal route in any framework, thus assign my 
SoapServer::handle() to a variable in the output, that's impossible because it's 
send to the browser straight away. This breaks several things:

- The framework using Output Buffering 
- PHPUnit using Output Buffering.

Soap feels like php 4.0 and it's time to update it. My feature request: Have 
SoapServer::handle() return the string instead or make a new method that does 

Test script:
$classmap = array(...);
$server = new \SoapServer(
    __DIR__ . '/../Resources/config/Notification.wsdl',
    array('classmap' => $this->classmap)

$response = new Response();
$response->headers->set('Content-Type', 'text/xml; charset=ISO-8859-1');

// Sadly handle() prints the output rather than returning it -.-
$content = ob_get_length() > 0
    ? ob_get_clean()
    : '<?xml version="1.0" encoding="UTF-8"?><root><error>No soap response generated</error></root>';

Expected result:

Actual result:
Would be so much easier if I could just do:


$response = new Response();
$response->headers->set('Content-Type', 'text/xml; charset=ISO-8859-1');


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-09-04 07:04 UTC] guillaume dot lintot at laposte dot net
You can do it this way

   class \SoapServer2 extends \SoapServer{
      public function handle($soap_request = null){
         $output = ob_get_contents();
         return $output;

   $server = new \SoapServer2(
      __DIR__ . '/../Resources/config/Notification.wsdl',
      array('classmap' => $this->classmap));
   // ...
 [2013-09-04 07:20 UTC] kjarli at gmail dot com
Yes, it's possible somewhat like that, but it still requires me to use ob_* 
functions. ob_* functions bug unit-tests and pretty much everything else, they 
are very annoying to use and they conflict with a framework output buffer.

It only makes sense if it would return instead of print so that I can do with the 
content what ever I want.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Thu Jun 01 22:03:39 2023 UTC