This question already has answers here:
Only variables should be passed by reference
(12 answers)
Closed 7 years ago.
Having this:
...
private $responseBuffer = array();
...
and within this line:
$lm = end(array_values($this->responseBuffer));
I get
Error: Only variables should be passed by reference (2048)
as both end and array_values are built in and do not have a call-by-referenceI'm puzzled, any one an idea?
(purpose: get the latest value out of $responseBuffer)
end function receives the arguement by reference, do like this:
$var = array_values($this->responseBuffer);
$lm = end($var);
Related
This question already has answers here:
How do I pass variables and data from PHP to JavaScript?
(19 answers)
Send PHP variable to JavaScript function [duplicate]
(6 answers)
How to pass php variable to JavaScript function as parameter
(4 answers)
how to pass php variable to javascript?
(2 answers)
Closed 12 months ago.
I am having one onclick event with some paramters with it. But in some
cases i am getting double quaotes or space between strings. so getting
error of Uncaught SyntaxError: missing ) after argument list or
invalid token.
How to overcome with this issue. I tried to use array and trim the
variables but it wont work for me.
$stringArray = ['string 1', 'string'2','001'];
$concatenated = trim(implode(',',$stringArray));
E.g: I am getting 3 string like :
$data1 = 'surgery';
$data2 = 'Cardio'c';
$data3 = 'hopsital ab"cc';
<a id='changeState' onclick=editModal(\"". $data1 ."\",\"". $data2 ."\",\"".$data3."\");>Click Here</a>
Please help to resolve this issue.
This question already has answers here:
PHP: "... variables can be passed by reference" in str_replace()?
(3 answers)
Closed 7 years ago.
What is causing this error?
Fatal error: Only variables can be passed by reference in /var/www/application
/lib/testing/imageMaker/imageMaker.php on line 24
$x=str_replace ($s1,'',$s2);
$y=str_replace ($s1,'',$s2, 1 ); //Line 24
As described here: PHP Manual: str_replace
count
If passed, this will be set to the number of replacements performed.
You cannot pass the literals and rather pass the reference:
$x=str_replace ($s1,'',$s2);
$y=str_replace ($s1,'',$s2, $count);
echo $count;
This question already has answers here:
Parse query string into an array
(12 answers)
Closed 8 years ago.
My chain in PHP is like the following:
$chain = "m=toto&i=12&a=new";
How to get m, i and a values ?
Thanks.
Try This:
<?php
$chain = "m=toto&i=12&a=new";
parse_str($chain,$array);
This will create an array named $array containing all values you can access them as $array['m']
You can Print all this by:
print_r($array);
This question already has answers here:
Anonymous recursive PHP functions
(6 answers)
Closed 9 years ago.
i need to recursively call a variable function, how can i do this?
$rec = function($li) use($html,$rec) { // error, rec was not defined yet
if( ... ) $rec( ... );
}
how can i do this?
Use the function variable $rec by reference (&$rec) so you can set it to the function then. This will also define it.
use($html, &$rec)
^
You find this principle outlined in the question Anonymous recursive PHP functions.
This question already has answers here:
What does it mean to start a PHP function with an ampersand?
(3 answers)
Closed 7 years ago.
I know & is used to create references.
But I wonder what having a & before a function name means:
function &DB($params = '', $active_record_override = FALSE) { // code }
It returns the result by reference. See the manual entry for it here.