Skip to content

Add deprecated userspace functions #244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from

Conversation

pp3345
Copy link
Contributor

@pp3345 pp3345 commented Dec 23, 2012

Since PHP 5.3.0 it is possible to mark functions and methods as deprecated by using the ZEND_ACC_DEPRECATED flag. Calling a function that has this flag emits an E_DEPRECATED error telling the user that this function is deprecated and its use should be avoided. However, it is not possible to give this flag to a userspace function, you can only throw an error yourself. Since it is common for large frameworks to deprecate old functions and remove them in later versions I believe that it would be useful if there was a cleaner way of marking a function as deprecated by preceding the function declaration with a "deprecated" modifier.

This patch adds such functionality. A new T_DEPRECATED ("deprecated") token is added and the ZEND_ACC_DEPRECATED flag is given to every function entry declared using the T_DEPRECATED token. It works both with normal functions and class methods. Giving the deprecated modifier to an object property or declaring multiple deprecated modifiers for a single function will lead to a E_COMPILE_ERROR. Tests are included.

It would be great if this patch would be accepted for PHP 5.5. In case I need to create a RFC or something please tell me.

@nikic
Copy link
Member

nikic commented Dec 23, 2012

This is a language change, so it will require an RFC.

Personally I'm against this as I don't see much use for it. I think if you are going to throw a deprecation warning, then I'd rather use the already existing E_USER_DEPRECATED with a custom message that can for example suggest alternatives.

@lstrojny
Copy link
Contributor

The only reason a deprecated keyword would be a good idea is reflection (and therefore e.g. IDEs can strike-through those symbols). But most IDEs already respect @deprecated, so I don’t really see a use case for it. A good enough way to deprecate functions is to do this

/**
 * @deprecated
 */
function deprecated_function() {
    trigger_error("deprecated_function() is deprecated. Use undeprecated_function() instead", E_USER_DEPRECATED);
    ...
}

This is obviously just my opinion, so if you want to go on, an RFC would be the next step.

@pp3345
Copy link
Contributor Author

pp3345 commented Dec 24, 2012

I know that it is already possible to throw a custom E_USER_DEPRECATED error. However, I think a deprecated modifier for functions would be a cleaner, faster and more obvious way of deprecating functions. If developers can simply add the ZEND_ACC_DEPRECATED flag to native functions, why should it not be possible for userspace functions too? Why do userspace developers need to throw an error themselves while a native function only needs a specific flag?

E_USER_DEPRECATED could rather be used for deprecating specific ways of calling a function or for deprecating whole libraries.

I've already requested write access to the Wiki in order to create an RFC but I am still waiting for the request to be accepted.

@pp3345
Copy link
Contributor Author

pp3345 commented Dec 25, 2012

I have created an RFC at https://wiki.php.net/rfc/deprecated-modifier.

@nikic
Copy link
Member

nikic commented Dec 26, 2012

@pp3345 Could you please write a mail to internals about the RFC?

@lstrojny
Copy link
Contributor

@pp3345 any news?

@pp3345
Copy link
Contributor Author

pp3345 commented Jan 14, 2013

There was a discussion on php.internals about this, see http://news.php.net/php.internals/64435 - Though only some developers shared their opinions, most of them seemed to dislike the idea. However, we still could give it a try and move the RFC to voting.

@dsp
Copy link
Member

dsp commented Mar 19, 2013

Any news on how to move forward with this? Are you going to vote on this or is this PR obsolete now?

@m6w6
Copy link
Contributor

m6w6 commented Oct 9, 2013

Ping @pp3345

@IngwiePhoenix
Copy link

@pp3345 Any news on that one? I personaly would really like this o.o

@smalyshev smalyshev added the RFC label Nov 18, 2014
@smalyshev
Copy link
Contributor

No news for more than a year, so I guess this is abandoned. If someone wants to pick it up, please take over the RFC and open the new pull req.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants