|  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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
38 - 3 = ?
Subscribe to this entry?

 [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-2024 The PHP Group
All rights reserved.
Last updated: Mon Jul 15 09:01:28 2024 UTC