Only variables should be passed by reference
Assign the result of explode
to a variable and pass that variable to end
:
$tmp = explode('.', $file_name);
$file_extension = end($tmp);
The problem is, that end
requires a reference, because it modifies the internal representation of the array (i.e. it makes the current element pointer point to the last element).
The result of explode('.', $file_name)
cannot be turned into a reference. This is a restriction in the PHP language, that probably exists for simplicity reasons.
Notice: Only variables should be passed by reference
bind_param
takes values by reference. It does this by looking at the variable you're passing and pointing at the innards directly.
In your call, you're returning the string result of a function call - password_hash in this case. Because there's no variable involved, there are no innards to point to. PHP is whining about not being able to pass the data by reference as a result.
You will need to stick the result of the function call into a variable, then pass that variable into the bind instead.
Try this:
$password = password_hash($_POST['password'], PASSWORD_BCRYPT);
$stmt->bindParam(':password',$password );
Credit: Here
Strict Standards: Only variables should be passed by reference error
This should be OK
$value = explode(".", $value);
$extension = strtolower(array_pop($value)); //Line 32
// the file name is before the last "."
$fileName = array_shift($value); //Line 34
PHP Strict Standards: Only variables should be passed by reference in .lib
This error happens because some functions not only return values but also (try to) change passed parameters (these params need to be passed by reference, because otherwise their value would be copied and there would be no effect outside function scope).
For example reset()
returns first element, but also changes internal array pointer (current elemtent). If you pass an array not assigned to any variable (direct result of the function call) the pointer cannot be set, because this array in outer scope doesn't longer exist. To fix line 309
you need to split command into variable assignment and then pass it to reset function:
$event_list = event_list(array('artikul_id' => $event_artikul_ids), ' AND point_id > 0');
$event = reset($event_list);
Same error in line 87
(needs if
with braces though).
The problem in line 155
is caused by html_rating_div_str()
function. For some reason it also requires reference - its definition might look like:
function html_rating_div_str(&$array, $users_data, $string) {...}
...with &
before one of the variables. The referenced parameter should be changed to variable first, and then passed to this function.
php Only variables should be passed by reference in error
The question itself is already answered by El_Vanja in the comments, but given you're beginner, I'd suggest to separate the evaluation of your variables from returning the outcome of that evaluation. That way, your code would become more readable, thus more maintainable, and easier to refactor - leaving you with far more room to improve both your code and your coding abilities.
The ternary operator, for example, is best suited for one-liners, while in your case you might resort to plain ol' if
clauses. It's a pretty verbose example, but you could approach evaluating your variables more along the lines of:
function _is_compiled(&$template_path, &$compile_path) {
if (!is_file($compile_path)) {
return false;
}
$template = file($compile_path);
$matches = preg_match(
'#^<\?php /\* Template_ 1.0.0 (\d+) ([^*]+) \*/#',
array_shift($template),
$match
);
if (!$matches) {
return false;
}
if ($match[1] != filemtime($template_path)) {
return false;
}
if ($match[2] != $template_path) {
return false;
}
$USET = new UserSet;
$tmp = $USET->readSet('sttime');
if ($tmp['setuptime'] > filemtime($template_path))) {
return false;
}
return true;
}
How brief or verbose you should be is a discussion as old as coding I suppose, but one interesting take on the topic is this one:
- https://jshakespeare.com/code-isnt-poetry/
Only variables should be passed by reference error
array_shift is a function that is acting on references.
If you pas in an array you will in fact edit that variable itself.
If you pass in something that is not a variable, then you don't have any further reference to what you pass in, hence the error.
he fact that the function is called by reference simply has no effect when not used with a variable and that's what you're being warned about.
The solution is simple, instead of passing
array_slice($courses, 0, 1)
directly ...
first create a variable $b = array_slice($courses, 0, 1);
and then pass that:
$semester = array_shift($b)->getSemester();
Only variables should be passed by reference error
You can't pass along the return value of a function to end()
.
Make it:
$arrayVar = explode(".", $file["name"]);
$extension = end($arrayVar);
You would have the same issue with other PHP functions. For example empty(someFunction())
would not work.
Strict Standards: Only variables should be passed by reference
You can try this code:
<?php
<?php
function scanDirectoryImages($directory, array $exts = array('jpeg', 'jpg', 'png'))
{
if (substr($directory, -1) == 'uploads/') {
$directory = substr($directory, 0, -1);
}
$html = '';
if (
is_readable($directory)
&& (file_exists($directory) || is_dir($directory))
) {
$directoryList = opendir($directory);
while($file = readdir($directoryList)) {
if ($file != '.' && $file != '..') {
$path = $directory . '/' . $file;
if (is_readable($path)) {
if (is_dir($path)) {
return scanDirectoryImages($path, $exts);
}
$path_info = pathinfo($path);
$ext = strtolower($path_info['extension']);
if (is_file($path) && in_array($ext, $exts)) {
$html .= '<a href="' . $path . '"><img src="' . $path
. '" style="max-height:100px;max-width:100px" /></a>';
}
}
}
}
closedir($directoryList);
}
return $html;
}
Related Topics
Session_Start() Creates New Session Every Refresh
Asynchronous Processing or Message Queues in PHP (Cakephp)
Whats the Best Way to Do User Authentication in PHP
How to Discover Rss Feeds for a Given Url
Learning Select from Where Prepared Statements
Dyld: Library Not Loaded: /Usr/Local/Lib/Libjpeg.8.Dylib - Homebrew PHP
Comparing Bcrypt Hash Between PHP and Nodejs
Is This the Correct Way to Send Email with PHP
Troubleshooting "No Such File or Directory" When Running 'PHP App/Console Doctrine:Schema:Create'
How to Validate on Max File Size in Laravel
Why Are Escape Characters Being Added to the Value of the Hidden Input
Tell Selinux to Give Apache Execute Access to PHP Files Outside Document Root
JSON_Encode/JSON_Decode - Returns Stdclass Instead of Array in PHP
Transpose Multidimensional Array and Join Values with Commas
Send Email with a Template Using PHP