php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32833 Invalid opcode
Submitted: 2005-04-26 12:11 UTC Modified: 2005-04-27 14:20 UTC
From: jason at amp-design dot net Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5CVS-2005-04-26 (dev) OS: CentOS 4 / RHEL 3
Private report: No CVE-ID: None
 [2005-04-26 12:11 UTC] jason at amp-design dot net
Description:
------------
Trying to concatenate on to a new/empty array element with the array push assignment operator, [] =, causes PHP to create a fatal error.

This is tested with the CVS snapshot http://snaps.php.net/php5-200504260830.tar.gz

Although the code I have given below is technically not correct because you can not concatenate a string on to an empty/new array element, it should be seen as an warning and not a fatal error (See notes on expected result). Also, the error is not very descriptive from a end user's point of view. I assume the invalid opcode error is obviously a generic error message that is used by you guys at Zend for debugging.

Previous versions of PHP seem to inconsistent. The reproducable code doesn't even give me a warning message when tested under PHP5.0.4. Surely it would be right to make this consistent with concatenating an undefined variable, by making a "Notice: Undefined variable: test[]" error.

Reproduce code:
---------------
<?php 
$test = array();
$test[] .= 'blah';
?>

Expected result:
----------------
Some form of warning stating that you can not concatenate to an empty/undefined array element. This should be consistent with the fact that if you did...

<?php
$f .= 'foo bar';
?>

that you would get a warning message because $f has not been defined before. (i.e. Notice: Undefined variable: f)

Actual result:
--------------
Fatal error: Invalid opcode 30/16/8

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-26 13:28 UTC] tony2001@php.net
Confirmed with HEAD only.
 [2005-04-26 15:55 UTC] jason at amp-design dot net
I don't know what is defined by 'HEAD', but I have I have tested this bug on older versions of of the PHP 5.1 branch admittedly they are only a week or so old, as well as the latest snapshot and I get the same problem. 

It doesn't happen on 5.0.4 or older. HOWEVER... older versions of PHP also have inconsistent behavior, as the test code surely should display a notice / warning... much like 

<?php
$f .= 'foo bar';
?>

produces a notice on version 5.0.4 and probably other older versions.
 [2005-04-27 14:20 UTC] dmitry@php.net
Fixed in CVS HEAD.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC