Home > Mobile >  PHP Error Was encountered, and I can not debug it myself
PHP Error Was encountered, and I can not debug it myself

Time:10-14

I am struggling to debug a PHP error I am getting when uploading photos to my website. It is not WordPress btw. The error message says "A PHP Error was encountered, Severity: Notice Message: Only variables should be passed by reference Filename: admin/vehicles.php Line Number: 322"

Below is the line of text from that file and line 322. I'm not sure if this is enough info to go off of, but if it's a simple syntax error, I'm sure it is.

 $ext = array_pop(explode('.', $_FILES['slider_image']['name']));

Thanks in advance! I can provide more of the code if needed.

CodePudding user response:

array_pop expects an actual variable, not a returned array, because it works with a pointer.

Try this:

$array = explode('.', $_FILES['slider_image']['name']);
$ext = array_pop($array);

Just to expand a bit on that:

If you use explode('.', $_FILES['slider_image']['name']);, you get an array. However, this array doesn't really exist. Its basically homeless. When you assign it to a variable, it gets an actual "address" in the memory.

array_pop only accepts references, not values (this is known as "pass by reference" vs "pass by value"). So you don't give array_pop a value, but the address to the value. These functions usually have a & sign in front of the variable name in the function definition.

https://www.php.net/manual/en/function.array-pop.php

  • Related