php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51249 str_replace instability causing irelevant fatal error
Submitted: 2010-03-09 20:24 UTC Modified: 2010-03-09 22:18 UTC
From: adrien dot crivelli at gmail dot com Assigned:
Status: Not a bug Package: Strings related
PHP Version: 5.3.2 OS: win xp
Private report: No CVE-ID: None
 [2010-03-09 20:24 UTC] 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">&nbsp;</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-&gt;__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 />


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-03-09 22:18 UTC] jani@php.net
-Status: Open +Status: Bogus
 [2010-03-09 22:18 UTC] jani@php.net
This is not Zend support forum.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 21:01:36 2024 UTC