From:
Operating system: win xp
PHP version: 5.3.2
Package: Strings related
Bug Type: Bug
Bug description:str_replace instability causing irelevant fatal error
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 bug report at http://bugs.php.net/bug.php?id=51249&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=51249&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=51249&r=trysnapshot53
Try a snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=51249&r=trysnapshot60
Fixed in SVN:
http://bugs.php.net/fix.php?id=51249&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=51249&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=51249&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=51249&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=51249&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=51249&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=51249&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=51249&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=51249&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=51249&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=51249&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=51249&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=51249&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=51249&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=51249&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=51249&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=51249&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=51249&r=mysqlcfg