#6294: Trying to get property of non-object [CORE/cake/libs/xml.php, line 601] --------------------------+------------------------------------------------- Reporter: olafnorge | Owner: Type: Bug | Status: reopened Priority: Medium | Milestone: 1.2.x.x Component: Core Libs | Version: 1.2 Final Severity: Trivial | Resolution: Keywords: | Php_version: PHP 5 Cake_version: | --------------------------+------------------------------------------------- Changes (by olafnorge):
* status: closed => reopened * resolution: needmoreinfo => Comment: This is an example array for what I'm trying to create xml. {{{ $xml = array( array('node' => array( 'tag1' => 'value1', 'tag2' => 'value2', 'tag3' => 'value3', 'tag4' => '', 'tag5' => 35, ), ), array('node' => array( 'tag1' => 'value1', 'tag2' => 'value2', 'tag3' => 'value3', 'tag4' => array( 'subtag4_1' => 'subvalue4_1', ), 'tag5' => 2, ), ), ); }}} Same array as a dump {{{ Array ( [0] => Array ( [node] => Array ( [tag1] => value1 [tag2] => value2 [tag3] => value3 [tag4] => [tag5] => 35 ) ) [1] => Array ( [node] => Array ( [tag1] => value1 [tag2] => value2 [tag3] => value3 [tag4] => Array ( [subtag4_1] => subvalue4_1 ) [tag5] => 2 ) ) ) }}} I call the construct of the XML-class with the $xml-array as the first parameter and the second parameter is an array which tells the construct what the name of the root-element should be (as you can see at my description above). The xml will be created correctly but there's always a notice at line 601 as you also can see at my description. Here is some more code of the xml-library. {{{ 587 if ($tag) { 588 if ($options['whitespace']) { 589 $d .= str_repeat("\t", $depth); 590 } 591 592 $d .= '<' . $this->name(); 593 if (count($this->namespaces) > 0) { 594 foreach ($this->namespaces as $key => $val) { 595 $val = str_replace('"', '\"', $val); 596 $d .= ' xmlns:' . $key . '="' . $val . '"'; 597 } 598 } 599 600 $parent =& $this->parent(); 601 if ($parent->name === '#document' && count($parent->namespaces) > 0) { 602 foreach ($parent->namespaces as $key => $val) { 603 $val = str_replace('"', '\"', $val); 604 $d .= ' xmlns:' . $key . '="' . $val . '"'; 605 } 606 } 607 608 if (is_array($this->attributes) && count($this->attributes) > 0) { 609 foreach ($this->attributes as $key => $val) { 610 $d .= ' ' . $key . '="' . htmlspecialchars($val, ENT_QUOTES, Configure::read('App.encoding')) . '"'; 611 } 612 } 613 } }}} Have a look at the lines 600 and 601. The variable ''$parent'' gets the reference of ''$this->parent()'' assigned. But if there is no such parent then no reference could be assigned. And if no reference was assigned there could not be any object. To avoid a call on non existing object I added the is_object-question to the if-clause. What should I test? Either there is an object then I can call it's attributes or there isn't an object and I can't call any function or attributes. I don't think there's any need for a testcase. I think the bug and the fix is pretty straight forward. -- Ticket URL: <https://trac.cakephp.org/ticket/6294#comment:2> CakePHP : The Rapid Development Framework for PHP <https://trac.cakephp.org/> Cake is a rapid development framework for PHP which uses commonly known design patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC. Our primary goal is to provide a structured framework that enables PHP users at all levels to rapidly develop robust web applications, without any loss to flexibility. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "tickets cakephp" group. To post to this group, send email to tickets-cakephp@googlegroups.com To unsubscribe from this group, send email to tickets-cakephp+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/tickets-cakephp?hl=en -~----------~----~----~----~------~----~------~--~---