php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26368 Returns a Fatal error when using assign-ops
Submitted: 2003-11-23 15:03 UTC Modified: 2003-11-23 21:21 UTC
From: webmaster at x7chat dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.3.3 OS: Linux, Windows
Private report: No CVE-ID: None
 [2003-11-23 15:03 UTC] webmaster at x7chat dot com
Description:
------------
A certain script I wrote uses the following line of code:

$USER['TEMP'] .= "!";

When I run this some servers (Programmed on Redhat Linux 9 with PHP 4.3.3 and it works fine, tested on another Linux server using PHP 4.3.3 and it returns the error) it returns the following error message:

Fatal error: Cannot use assign-op operators with overloaded objects nor
string offsets in
(FILE PATH) on line (LINE NUMBER)

I have asked many different programmers about it and nobody has an answer as to why it causes an error on code that is correct.  According to PHP documentation the syntax of it is correct.  

Another person who has had this problem has documented it here: http://www.faqchest.com/prgm/php-l/php-02/php-0205/php-020581/php02052416_25320.html.  I distribute the script for free and I have had at least 4 different users report that they are having this problem.

The variable $USER['TEMP'] has been defined before and is not null.

Reproduce code:
---------------
$q = DoQuery("SELECT * FROM $SERVER[TBL_PREFIX]users WHERE username='$USER[NAME]'");
$USER['TEMP'] = $row[13];
$k = 1; $i = 0; $s = 0; $r[0] = "";
$USER['TEMP'] .= "!";
while($k){
$sub = substr($USER['TEMP'],$i,1);
if($sub == "!"){
$k = 0;
break;
}
if($sub == ","){
$s++;
}else{
@$r[$s] .= $sub;
}
$i++;
}

Expected result:
----------------
I would expect it to add "!" to $USER['TEMP'] every time it goes through the while loop, on some servers it does but on others it returns the error even if they are the same type of server running the same version of PHP.

Actual result:
--------------
On some servers it works correctly and on others it says:

Fatal error: Cannot use assign-op operators with overloaded objects nor
string offsets in
(FILE PATH) on line (LINE NUMBER)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-11-23 21:21 UTC] sniper@php.net
You have some problem in your script. Get rid of '@' and set error_reporting(E_ALL); and you'll most likely find out what is wrong. There is no bug here, this is expected behaviour.

 [2004-09-23 01:41 UTC] penfield888 at yahoo dot com
Actually, I have error_reporting set to E_ALL, no error suppression operators, all variables carefully initialized.  I get the error on occasion on one server, not on others.  In a very simple situation, I get the same error on code like this

$var['idx'] = '';
$var['idx'] .= "more string";

Others who have had the error seem to have had goodluck fixing it simply by changing to

$var['idx'] = $var['idx'] . "more string";

which should change nothing.
 [2011-05-24 01:58 UTC] cindy dot dolan at yahoo dot com
I have the same issue at PHP 5.3.5, and the same fix. 

Looping through the output of a database query, I collect data on two things - CPU & Memory - into two arrays.  Each is initialized identically. 
  Data is collected like:  $cpu[$cntr] .= "<some more xml data>";  The memory data is collected identically:  $mem[$cntr] .= "<some more xml data>";

When I comment out the memory-related array data collection, the code runs fine.  
When I include it, I get this crazy error.
When I change the syntax to:
  $mem[$cntr] = $mem[$cntr] . "new data";
it runs fine.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 02:01:30 2024 UTC