-5

Possible Duplicate:
Annoying PHP error: “Strict Standards: Only variables should be passed by reference in”

I have this line of code,

$extension=end(explode(".", $srcName));

when I fun my function I get

PHP Strict Standards: Only variables should be passed by reference in

I am not sure how to solve this

Community
  • 1
  • 1
Justin Erswell
  • 688
  • 7
  • 42
  • 87
  • 1
    Related: [Parentheses altering semantics of function call result](http://stackoverflow.com/q/6726589/367456) – hakre Nov 02 '12 at 14:43

1 Answers1

4

The function end() requires a variable to be passed-by-reference and passing the return-value of a function doesn't acheive this. You'll need to use two lines to accomplish this:

$exploded = explode(".", $srcName);
$extension = end($exploded);

If you're simply trying to get a file-extension, you could also use substr() and strrpos() to do it in one line:

$extension = substr($srcName, strrpos($srcName, '.'));

Or, if you know the number of .'s that appear in the string, say it's only 1, you can use list() (but this won't work if there is a dynamic number of .'s:

list(,$extension) = explode('.', $srcName);
newfurniturey
  • 37,556
  • 9
  • 94
  • 102
  • 2
    *Pssst:* If it's about the file-extension, better link a question that is specifically about it. Like: [How to extract a file extension in PHP?](http://stackoverflow.com/q/173868/367456) – hakre Nov 02 '12 at 14:45
  • Billiant simple solution, makes sense and really helped me out there, thanks nefurniturey – Barry Connolly May 10 '13 at 10:07