Edit report at http://bugs.php.net/bug.php?id=51249&edit=1
ID: 51249 Updated by: [email protected] Reported by: adrien dot crivelli at gmail dot com Summary: str_replace instability causing irelevant fatal error -Status: Open +Status: Bogus Type: Bug Package: Strings related Operating System: win xp PHP Version: 5.3.2 New Comment: This is not Zend support forum. Previous Comments: ------------------------------------------------------------------------ [2010-03-09 20:24:12] adrien dot crivelli at gmail dot com Description: ------------ usage of str_replace() as described below produce the expected result the first time it is called (a select box with 3 choices), but it then introduce incoherent/unstable state within PHP who cannot correctly serve any further request and producing irrelevant warnings. It would seems to me that PHP is not able to correctly create new objects after the first request as any access to "$this" produce a warning. This was reproduced with XAMPP Lite for Windows 1.7.3 and Zend Framework 1.9. I am not in position to try on linux version but will do soon and report back... Test script: --------------- <?php require_once('Zend/View.php'); require_once('Zend/Form.php'); require_once('Zend/Form/Element/Select.php'); function foo() { $form = new Zend_Form(); $element = new Zend_Form_Element_Select('selectbox', array('multiOptions' => array('group 1', 'group 2', 'group 3'))); $form->addElement($element); $form->setView(new Zend_View()); return $form; } echo str_replace('group', 'replaced', foo()); // Will introduce unstable state echo str_replace('group', 'replaced', (string)foo()); // Always working fine ?> Expected result: ---------------- It should always return this, no matter how many times we access the page: <form enctype="application/x-www-form-urlencoded" action="" method="post"><dl class="zend_form"> <dt id="selectbox-label"> </dt> <dd id="selectbox-element"> <select name="selectbox" id="selectbox"> <option value="0" label="replaced 1">replaced 1</option> <option value="1" label="replaced 2">replaced 2</option> <option value="2" label="replaced 3">replaced 3</option> </select></dd></dl></form> Actual result: -------------- The second time the page is visited, we have: <br /> <b>Warning</b>: Attempt to assign property of non-object in <b>C:\xampplite\ZendFramework\library\Zend\Form\Element.php</b> on line <b>468</b><br /> <br /> <b>Warning</b>: Attempt to assign property of non-object in <b>C:\xampplite\ZendFramework\library\Zend\Form\Element\Multi.php</b> on line <b>208</b><br /> <br /> <b>Warning</b>: Attempt to assign property of non-object in <b>C:\xampplite\ZendFramework\library\Zend\Form\Element\Multi.php</b> on line <b>209</b><br /> <br /> <b>Fatal error</b>: Uncaught exception 'Zend_Form_Exception' with message 'Zend_Form_Element requires each element to have a name' in C:\xampplite\ZendFramework\library\Zend\Form\Element.php:253 Stack trace: #0 C:\xampplite\htdocs\okpilot\htdocs\admin\news.php(9): Zend_Form_Element->__construct('selectbox', Array) #1 C:\xampplite\htdocs\okpilot\htdocs\admin\news.php(16): foo() #2 {main} thrown in <b>C:\xampplite\ZendFramework\library\Zend\Form\Element.php</b> on line <b>253</b><br /> ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=51249&edit=1
