[wp-forums] PHP 5.4 pass-by-reference errors

Doug Sparling doug.sparling at gmail.com
Wed Dec 25 00:43:54 UTC 2013


I know I'm preaching to the choir, but this was deprecated years ago (at
least PHP 5.3.0, in 2009) and developing plugins with DEBUG=1 would have
displayed a warning saying such, though I suppose it's still a choice by
the developer. (I'm saying developers should have got this, not end users.)
Granted, I rarely see deprecated functions actually disappear, but that is
the intended meaning of a deprecation. However, though I like to make sure
there are no warning or errors before I release a plugin, I imagine I've
been guilty as charged a few times... :)


On Tue, Dec 24, 2013 at 2:15 PM, Otto <otto at ottodestruct.com> wrote:

> You're probably going to start seeing some of this in the forums. I
> saw a couple this morning.
>
> With some hosts going to PHP 5.4, a fatal error is going to start
> cropping up in older code. It's the call-time pass-by-reference error.
> It should look like this:
>
> PHP Fatal error: Call-time pass-by-reference has been removed in ... on
> line 123
>
> This occurs when there is a function call that looks like the following:
>
> someFunctionCall( &$var );
>
> The & ampersand symbol is not valid in a function call anymore. It has
> been deprecated since PHP 5.0, but now in 5.4 it causes a fatal error.
> In 5.3 it only caused a warning which would be ignored most of the
> time.
>
> The general fix to simply remove the & ampersand. This usually solves
> it. In a theme, this is almost always the only thing you have to do.
>
> In some rare cases, this may cause a deeper underlying problem if the
> code really needed that variable to be passed by reference. In which
> case, the function definition would need to be modified as well.
>
> It's like this:
>
> example( &$var );
> function example( $var) {
> ...
> }
>
> Would become:
>
> example( $var );
> function example( &$var ) {
> ...
> }
>
>
> However, this is only needed with pass-by-reference is necessary,
> which it is usually not.
>
> More details:
> http://php.net/manual/en/language.references.pass.php
>
> So, if you see somebody complaining about 5.4 incompatibility, get the
> error message from them, tell them to look at that line, and remove
> the & ampersand.
>
> -Otto
> _______________________________________________
> wp-forums mailing list
> wp-forums at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-forums
>


More information about the wp-forums mailing list