PHP and passing non-variables by reference

Tags: •  • 

In PHP 5.0.5, they’ve now made it a requirement that things that are passed by reference must now explicitly be a variable. You would think this kind of behavior is obvious, but apparently it’s been allowed for all versions of PHP previous. Appararently without even warnings. You’ll get an error:

Fatal error: Only variables can be passed by reference ...

So you may think, where is this useful? Consider something short and concise like:

$onlyelementwecareabout = array_pop(explode($seperator, $string));

You cannot do this now. The return value of a function is not a “variable” and cannot be passed by reference; a temporary variable needs to be used instead:

$temporyvariable = explode($seperator, $string); $onlyelementwecareabout = arraypop($temporary_variable);

Yes, there are other ways to do the above, but that isn’t the point. The fix is not difficult, but it is a total complete pain to go back to legacy code and fix things like this.

Remind me to find another web programming language.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

web programming languages

Python - need I say more?

check out http://cherrypy as a framework, or http://turbogears.org, which builts on CherryPy. S


I like Python a lot, but the

I like Python a lot, but the web development frameworks are still way too fragmented.

I’ve seen and worked with TurboGears—and I like what I’ve seen so far. But at the moment, my main issue is that it’s not done yet. It’s not stabilized—there have been many API changes so far, which is my original complaint with PHP…

So, time will tell.


Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text.
  • Images can be added to this post.
  • You may use [inline:xx] tags to display uploaded files or images inline.
More information about formatting options