homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

When can I combine or separate functions?

5+ Year Member

Msg#: 4608330 posted 4:02 pm on Sep 8, 2013 (gmt 0)

I don't know if it's terrible practice or not, but I often combine multiple functions on the same line instead of assigning a variable I'm only going to use once. Normally its not a problem, but I'm getting an "Only variables should be passed by reference" error for:

$name = array_shift(array_values(array_diff($candidates, $conflicts)));

I don't get an error if I break it into two lines:

$vettedCandidates = array_values(array_diff($candidates, $conflicts));
$name = array_shift($vettedCandidates);

I just don't understand what the difference is and why the first one gives me an error. To me, they would seem the same.



WebmasterWorld Senior Member 5+ Year Member

Msg#: 4608330 posted 12:11 pm on Sep 10, 2013 (gmt 0)

array_shift modifies the variable you pass into it.

If you look on the docs [uk3.php.net], it's shown as
array_shift ( array &$array )
- the leading ampersand there means it's a reference rather than a typical variable. A function call cannot be a reference.
Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved