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;
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:
What's the difference between an argument and a parameter?
(38 answers)
Closed 7 years ago.
I don't understand difference of arguments and parameter in function.Is there anybody who tell me details about arguments and parameters. What is arguments and what is parameter?
To be simple -
Variables used in function definition are parameter.
Values passed during function call are arguments
function abc($x)
{
//----
//$x is parameter..
}
abc(35); //35 is an argument
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);
This question already has answers here:
Error message "Strict standards: Only variables should be passed by reference"
(6 answers)
Closed 6 years ago.
I'm getting the following error:
Strict Standards: Only variables should be passed by reference in /home/bridgesh/public_html/includes/functions/html_output.php on line 45
From the following lines of code:
44. while ($val = current($new_get)){
45. if($val==end(array_reverse ($new_get)) )$new_getstr.='?'.key($new_get).'='.$val;
46. else $new_getstr.='&'.key($new_get).'='.$val;
47. next($new_get);
48. }
I've read through similar questions & answers on the subject here, but cannot figure out how to break the line down correctly.
end works on a reference to an array, so it expects a variable, that contains an array
array_reverse ($new_get) however is not a variable, but a function call
You have to do:
$reversed = array_reverse ($new_get)
if($val==end($reversed) )$new_getstr.='?'.key($new_get).'='.$val;
Try this:
$new_getstr = http_build_query($new_get);
Documentation
This question already has answers here:
Call dynamic Function with unknown number of params
(3 answers)
Closed 8 years ago.
I want to do something like that:
call_user_func(array('Class', 'Method'), implode(", ", $array));
Is it possible? The imploded string contains a couple of expressions. In this shape however, if $array contains 2 elements, I get an error that Class::method() needs 2 parameters, not 1.
How can I solve this?
You want call_user_func_array instead.
call_user_func_array(array('Class', 'Method'), $array);