php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67641 SoapFault Traversable ?
Submitted: 2014-07-17 11:50 UTC Modified: 2014-07-18 10:56 UTC
From: vosa at binaryparadise dot com Assigned:
Status: Not a bug Package: SOAP related
PHP Version: Irrelevant OS: debian
Private report: No CVE-ID: None
 [2014-07-17 11:50 UTC] vosa at binaryparadise dot com
Description:
------------
---
From manual page: http://www.php.net/class.soapfault
---
There's strange behavior of SoapFault instance when used in foreach construct. It behave almost like Transversable object, but it shouldn't. SoapFault extends Exception and none of these classes implements Transversable interface...

Test script:
---------------
print "Exception:\n";
foreach(new Exception('message') as $k => $v) 
    print "$k: $v\n";
    
print "SoapFault:\n";
foreach(new Soapfault('faultcode', 'faultstring') as $k => $v) 
    print "$k: $v\n";

Expected result:
----------------
Exception:
SoapFault:

Actual result:
--------------
Exception:
SoapFault:
faultstring: faultstring
faultcode: faultcode

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-07-17 19:29 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2014-07-17 19:29 UTC] requinix@php.net
Objects that are not Traversable can still be iterated over using a default behavior: the set of accessible properties and their values.

http://php.net/manual/en/language.oop5.iterations.php

As mentioned in a few places, SoapFault has undocumented properties "faultstring" and "faultcode". Adding that to the default foreach behavior results in the output you see.
 [2014-07-18 07:16 UTC] vosa at binaryparadise dot com
Your link about object iterations says: "By default, all visible properties will be used for the iteration."

"faultstring" and "faultcode" are NOT visible (or documented) properties. Developers don't want to search "in a few places", but in official PHP reference.

I think it's not much work to write few words in documentation about this "feature".
 [2014-07-18 09:14 UTC] requinix@php.net
>"faultstring" and "faultcode" are NOT visible (or documented) properties.
They certainly are visible. Undocumented, but visible.

>Developers don't want to search "in a few places", but in official PHP reference.
I'm not saying the docs are perfect as they are. I merely took the extra minute to do some research to see where those values were coming from - something I'd like to think other developers would do too.

I was kinda hoping you would make the doc bug for it, but I can do that:
 [2014-07-18 09:21 UTC] requinix@php.net
...and here is where I was expecting to see an automatic comment.

https://bugs.php.net/bug.php?id=67648
 [2014-07-18 10:56 UTC] vosa at binaryparadise dot com
Thank you
 [2014-07-18 11:02 UTC] vosa at binaryparadise dot com
And one thing:
"They certainly are visible. Undocumented, but visible." Not all of them:

<?php

print "SoapFault:\n";
foreach(new Soapfault(null, null) as $k => $v) 
    print "$k: $v\n";

// output:
// SoapFault:
// faultstring:

// or

print "SoapFault:\n";
foreach(new Soapfault(null, null, null, null, null, null) as $k => $v) 
    print "$k: $v\n";

// output:
// SoapFault:
// faultstring: 
// headerfault:
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Oct 28 04:01:23 2020 UTC