|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-05-17 11:02 UTC] mellow at mellow dot dk
I've build an array using the following in a function :
-------------
$this->get_data(array("","","and D.XiParentId= 'gwak_root_element' ORDER BY D.vcOrder"));
$arrCategory = $this->return_array();
for($i = 0 ; $i < sizeof($arrCategory) ; $i++) {
$this->get_data(array("","","and D.XiParentId = '" . $arrCategory[$i]["XiDataId"] . "' ORDER BY D.vcOrder"));
$arrItem[$arrCategory[$i]["vcItemId"]] = $this->return_array();
}
return $arrItem;
-------------
This constructs an array with values like :
$arrItem["project_priority"][0] = array(...)
$arrItem["project_priority"][1] = array(...)
etc...
Later I tried to do the following to the returned $arrItem :
-------------
$arrItem["project_severity"][] = array("XiDataId" => "gwak_get_all", "vcText" => "All");
-------------
This gives the error :
-------------
Fatal error: Cannot use [] for reading in /home/plb/public_html/gwak/module/project/include/Task.class.php on line 160
-------------
Funny because doing the following :
-------------
$arrThis["here"][] = array("XiDataId" => "asdasdas", "vcText" => "324234234");
$arrThis["here"][] = array("XiDataId" => "asdasdas", "vcText" => "324234234");
$arrThis["here"][] = array("tr" => "ert");
$arrThis["where"][] = array("er" => "ert");
$arrThis["where"][] = array("we" => "ert");
$arrThis["where"][] = array("tr" => "ert");
-------------
gives no error at all, eventhough $arrThis and $arrItem have exactly the same format. Do you guys have an idea what is going on here?
The only thing i can see could cause the problem is that $arrItem is built using "arrays within arrays":
$arrItem[$arrCategory[$i]["vcItemId"]] = array(...);
Can this be the cause or...
In advance thx...
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 00:00:02 2025 UTC |
I occured a similar error when using (also on lx-machine) while ($db->next_record()) { /* Fix for php 4.2.1 */ $foo=$db->f('RIS_VSR_FK'); $curstate[$foo] = $db->f('RIS_ALLOWED'); /* End Fix $curmain[$db->f('RIS_VSR_FK')] = $db->f('RIS_ISMAIN'); <-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1 $defmainvs = $db->f('RIS_ISMAIN') == 'YES' ? $db->f('RIS_VSR_FK') : $defmainvs; } Parse error: parse error, unexpected T_OBJECT_OPERATOR, expecting ']' in xxx on line 166 <-!!!!!!!!!!!! this line That means that accessing an object in a class instance and using this as the arrays index also does not work, using a simple variable does work. Probably there is a major bug in the parser (priority?), because the workaround with $array[{$array_b[1][2]}], which I would expect that first {$array_b[1][2]} is evaluated and then $array[$evaluation_result] gets the error that no {} are allowed. I am not sure this is a new bug, but I remember in 4.0.x it always worked fine.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.Seems to be a class related bug, here is a simple test-case: <?php // php 4.3.9 - CentOS 4.3 - oliver@samera.com.py - 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; } ?>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.