开发者

Will the global keyword be deprecated/dropped in future PHP versions?

开发者 https://www.devze.com 2023-02-08 07:41 出处:网络
I wou开发者_StackOverflowld be interested if the global keyword will be deprecated or dropped in future PHP versions.

I wou开发者_StackOverflowld be interested if the global keyword will be deprecated or dropped in future PHP versions.

I am taking care of some legacy applications which use something like this:

function foo($x)
{
    global $y;
}

quite often. I would like to know if I should start rewriting those lines in a different way or should it still work in next PHP releases?


I would be interested if the global keyword will be deprecated or dropped in future PHP versions.

While none of us can tell the future for certain, the most recent discussions (December 2010) on the topic gave a resounding, "No thanks!"

Have a read (61 messages) yourself: http://markmail.org/thread/y5aeyej7i72y4em4


I very much doubt the global keyword will ever be dropped from PHP, as it would require a massive rewrite for many, many applications and PHP has always been big on backward compatibility.

Also, different from real kludges like magic quotes, global is, even though discouraged, a valid language construct.

As far as I'm aware, there are no concrete plans or even serious discussions about it.

That said, it is generally a good thing not to use it, and work with function parameters or class properties instead.


I think, it will work in future versions (as back compatibility). But I recommend you to rewrite such functions, because globals is evil :)


Agreed. The chance of a sudden drop now is slim. You should still look to rewrite your own code to avoid global.

0

精彩评论

暂无评论...
验证码 换一张
取 消