开发者

What does PHP do with deprecated functions?

Getting these errors "Deprecated: Assigning the return value of new by reference is deprecated..."

While I know what deprecated function means, but I am not very clear that what PHP does to them? Still execute them as usual? So at this point for this function, does PHP silently assign memory location for the variable or still using reference pointer?

EDIT - thanks for the answers, I asked this question becaus开发者_运维问答e we are using adodb_lite and the library has not corrected error.


Deperecated functions still exist and you get the warning. So they work as expected. However in a future version they might disappear.

That's the same for other deprecated language features which you sometimes get notices about. It's a way to signal changes to users which have code based on an older PHP version.

Normally the deprecated features get removed after some time, but it's not predictable how long this takes. I know of at least one case where a once deprecated feature was un-deprecated later on. However, I think that's exceptional.

So if you see these warnings, update the code. Most often the PHP documentation has more information why something has been deprecated and what to do. Most often it's an improvement (e.g. in security), so you really should deal with these warnings if you care about the code.

Edit: I think it's noteworthy in this context to look for strict standards notices PHP Manual as well. They are somewhat related because these notices are useful hints for changes in the language as well.

Enabling E_STRICT during development has some benefits. STRICT messages will help you to use the latest and greatest suggested method of coding, for example warn you about using deprecated functions.

(from the PHP Manual link above)


They will proceed to run as documented, but they may be removed in the future and so should be converted as soon as possible in existing code, and not used in new code.


Deprecated features work, but there are better alternatives, and they may be removed in future versions of PHP.


I believe PHP continues to execute the function while additionally triggering an error stating that the function is deprecated.

Ye Olde Version:

function foo(){
  bar();
}

New Version:

function foo(){
  bar();
  trigger_error('Deprecated: this function is deprecated foo!', E_NOTICE);
}

Note: this is probably not what's actually happening behind-the-scenes, but it would be relatively equivalent.


Nothing, it's just a warning. Read it as "this function still works as documented for this version of PHP, but all bets are off in future versions". Internally there's no difference at all, except for adding the deprecation warnings.


They still get executed as 'normally'.

However you need to ditch them as fast as you can for you code to keep on working in the future.


Aside from emitting deprecation warnings, the code will work fine. The deprecation indicates the feature in question may be removed in the future.

This warning refers to a line like

$obj =& new MyClass();

The ampersand is not required any more since php 5; you can simply write

$obj = new MyClass();


The depreciated functions still exist however you get the warning, meaning that such functions will not be available in future.


They can be removed in later versions of php so don't use a shared server. This happened to me. My site was working fine until the service provider decided to 'upgrade' the version of php. Suddenly my site fell over in a big heap because the php people in their infinite wisdom decided to remove some functions.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜