+ 7

How to fix this error? Fatal error: Cannot use temporary expression in write context in C:\Program Files\index.php on line 1506

Please help me... I have an error inside for loop. $myArray=array(); $x=0; $result=''; sc_lookup(ds,"SELECT latitude,longitude FROM heatmap"); for($i=0;$i<count({ds});$i++){ myArray[0][]= "new google.maps.LatLng(".{ds[$i][0]} .",". {ds[$i][1]} .")"; //error in this line } $result = json_encode($myArray);

27th Mar 2018, 1:44 PM
Ankit Saxena
Ankit Saxena - avatar
2 Respostas
+ 2
As i can see, you only want to store the constructor string in the array? Your problem is, that ds is a constant and since PHP7 Expressions of type (...)[42] and [...][42] (and other cases where some dereferencing operation is applied to a non-variable) are now parsed as a variable (rather than expr_without_variable, as it was previously). This means that the expression will behave correctly in empty(). E.g. empty([]['a']) will no longer throw an undefined offset notice. Furthermore it is now possible to assign to expressions of this kind, for example (new Foo)->bar = 'baz' is now possible (thought doesn't make much sense unless Foo implements __set). well, try following: $_ds = ds; for($i=0;$i<count({$_ds});$i++){ array_push( $myArray[0], "new google.maps.LatLng({$_ds[$i][0]},{$_ds[$i][1]})" ) } // A better, nicer and cleaner approach would to transform your for- into a foreach loop.
27th Mar 2018, 2:46 PM
Jeff Block
Jeff Block - avatar
+ 6
No its not working, again the same error occurs
27th Mar 2018, 4:50 PM
Ankit Saxena
Ankit Saxena - avatar