From:             php at maisqi dot com
Operating system: Probably all
PHP version:      5.4.19
Package:          SimpleXML related
Bug Type:         Bug
Bug description:Non existent properties should be regular SimpleXMLElement 
objects

Description:
------------
When we invoke a non existent sub-node, SimpleXMLElement returns a
SimpleXMLElement object. But when we try to get a non existent sub-node on
that object, it returns NULL.
IMO this renderes it inconsistent.

Test script:
---------------
<?php
class XXX {

        public  function test () {
                $sx = new \SimpleXMLElement ('<x></x>');
                $node = $sx->node;
                echo '1: $node = $sx->node => ', $node === $this ? 'this' : 
gettype
($node) . ':' . get_class ($node), '   node->count: ', $node->count (),
"<br />\n";
                $node = $sx->node->node;
                echo '2: $node = $node->node => ', $node === $this ? 'this' : 
gettype
($node), "<br />\n";
        }
}


$x = new XXX;
$x->test ();


Expected result:
----------------
Or both ($sx and $node) SimpleXMLElement objects should return NULL for a
non existent sub-node or both sould return a SimpleXMLElement object. As it
is, it's a surprise lurking.

I think the second option is best. It makes things like this possible:

if ($products = $sx->Catalog->Products->Product) {
  // Never gets here if there's no <Catalog>, or if it has no sub-nodes
  // named <Products>, or if it has no sub-nodes named Product.
}
else die ('No products');

Actual result:
--------------
$node it's a SimpleXMLElement, then it is NULL.


1: $node = $sx->node => object:SimpleXMLElement   node->count: 0<br />
2: $node = $node->node => NULL<br />

-- 
Edit bug report at https://bugs.php.net/bug.php?id=65535&edit=1
-- 
Try a snapshot (PHP 5.4):   
https://bugs.php.net/fix.php?id=65535&r=trysnapshot54
Try a snapshot (PHP 5.3):   
https://bugs.php.net/fix.php?id=65535&r=trysnapshot53
Try a snapshot (trunk):     
https://bugs.php.net/fix.php?id=65535&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=65535&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=65535&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=65535&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=65535&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=65535&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=65535&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=65535&r=notwrong
Not enough info:            
https://bugs.php.net/fix.php?id=65535&r=notenoughinfo
Submitted twice:            
https://bugs.php.net/fix.php?id=65535&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=65535&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65535&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=65535&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=65535&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=65535&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=65535&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=65535&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=65535&r=mysqlcfg

Reply via email to