ID:               17290
 Comment by:       tomis at centrum dot cz
 Reported By:      mellow at mellow dot dk
 Status:           No Feedback
 Bug Type:         Scripting Engine problem
 Operating System: Linux
 PHP Version:      4.1.2
 New Comment:

If the problem is not the obvious one
i.e. $x = $my_array[]; which is wrong because empty [] are only for
setting, there can be this case(as posted by [18 Apr 2006 7:03pm UTC]
oliver at samera dot com dot py)
it is not a bug, but a way how PHP treats calling of variables
simple test case 
class A {
public $field = array();
public $field2 = array();
public function AddToField($fieldname, $item){
$this->$fieldname[] = $item;
}
}
this throws an error because PHP is trying to read fieldname WITH the
parenthsis 
so the workaround is to put 
$this->{$fieldname}[]=$item and it is working - it just helps compiler
what did you ment with $fieldname.


Previous Comments:
------------------------------------------------------------------------

[2008-09-16 17:22:58] naugtur at gmail dot com

I've had the same problem. It reported the error in line 26, but the
line was ok. I often try entering empty lines - it reveals if the error
is somewhere else. The problem with this error is just trying to read
something like this:
$somename[]

if you try:
$this=$thatarray[]; 
without putting something between [] you get this error. 

Everything would be ok if PHP reported it in correct line. Please fix
that! It would save people ages of looking the code through!

------------------------------------------------------------------------

[2007-07-20 21:56:05] asohn at aircanopy dot net

PHP 4.3.4
I got this error when mistakenly used "return $variable[];" instead of
"return $variable" in a user defined function.

------------------------------------------------------------------------

[2006-06-12 13:01:07] Matt_B at TinyOnline dot co dot uk

I've just had the same problem, from changing a variable from global,
to class specific. After some confusion I realised I forgot to remove
the $, just like in your example:

$this->$resultado_array[] should be
$this->resultado_array[]

and then it all works fine.

------------------------------------------------------------------------

[2006-04-18 19:03:41] oliver at samera dot com dot py

Seems to be a class related bug, here is a simple test-case:

<?php
// php 4.3.9 - CentOS 4.3 - [EMAIL PROTECTED] - 18-apr-2006

//
-----------------------------------------------------------------------------
class cache_db {
        var $resultado_array;

        function cache_db() {
                $this->$resultado_array = array();
        }

        // abre un archivo y lo carga en memoria
        function cache_open() {
                $archivo_array = array(array('1'), array('2'), array('3'));
                $resultado_array = array();

                foreach($archivo_array as $linea) {
                        $resultado_array[] = $linea;
                        $this->$resultado_array[] = $linea;
                }
        }
}

// without a class
$archivo_array = array(array('1'), array('2'), array('3'));
$resultado_array = array();

foreach($archivo_array as $linea) {
        $resultado_array[] = $linea;
}

?>

------------------------------------------------------------------------

[2006-03-18 21:17:37] 7l9it46r1adm1l1 at jetable dot com

I got the same strange Fatal error (using Windows XP, PHP PHP 5.0.4):
Fatal error: Cannot use [] for reading in ... on line 82

[php]
if ($insert->check($_POST['value']) === FALSE)
{
   $error[] == 'Error'; // line 82
}
[/php]

Zend Developer didn't give any warnings so there shouldn't be any
syntax mistakse in that PHP file.

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/17290

-- 
Edit this bug report at http://bugs.php.net/?id=17290&edit=1

Reply via email to