====== PHP RFC: Function Alias for class methods declaration ======
* Version: 1
* Date: 2025-07-24
* Author: Dmitrii Derepko, xepozzd@gmail.com
* Status: Draft (Later in the RFC process "Under Discussion", "Voting", and finally "Accepted", "Declined" or "Implemented")
* Implementation: https://github.com/...
===== Introduction =====
Modern languages use short constructions to boost developer experience. PHP as a modern language should follow in steps as well and re-use best practices of the others. I would like to make the fn keyword available to declare class methods.
Modern languages, such as Kotlin, Rust, Python use short function declaration keywords such as fn, fun, def.
PHP uses function which is 4x longer that fn, which is already in use in other parts of the language, such as closures.
===== Proposal =====
Make fn keyword fully aliased for class methods:
This is fully equivalent to
==== Examples ====
Remember that the RFC contents should be easily reusable in the PHP Documentation. This means, if at all possible, they should be runnable as standalone, self-contained code with the proof-of-concept implementation.
Simple example:
Example showing an edge case:
===== Backward Incompatible Changes =====
- Breaks backward compatibility because of new syntax construction.
===== Proposed PHP Version(s) =====
PHP 9.0
===== RFC Impact =====
==== To the Ecosystem ====
What effect will the RFC have on IDEs, Language Servers (LSPs), Static Analyzers, Auto-Formatters, Linters and commonly used userland PHP libraries?
==== To Existing Extensions ====
Will existing extensions be affected?
==== To SAPIs ====
Describe the impact to CLI, Development web server, embedded PHP etc.
===== Open Issues =====
Make sure there are no open issues when the vote starts!
===== Future Scope =====
- [RFC] Function Alias for function declaration
Modern languages provide developers simple ways to define most popular constructions, such as short constructors, short functions, omitting mindless keywords and etc.
This RFC make PHP a step closer to a modern PHP look:
1;
fn doProxy() {
return $this->service->main();
}
}
?>
Instead, classic syntax is still available and much verbose:
service->main();
}
}
?>
This examples uses short constructor RFC syntax, single expression function syntax and have function -> fn alias
===== Question / Answer =====
==== Should be "function" deprecated? ====
Yes, it should, but with no deprecation warning. Modern codebase will use short syntax (on demand), old projects/libraries won't be re-writed, so classic "functions" should live longer.
==== Will single function declaration be affected as well? ====
Yes, in another RFC.
==== Can I use both fn and function keywords in the same class? ====
Yes, as you wish:
As it's fully-alised it can be replaced vise-versa. The reason to use it so is up to you.
===== Voting Choices =====
Pick a title that reflects the concrete choice people will vote on.
Please consult [[https://github.com/php/policies/blob/main/feature-proposals.rst#voting|the php/policies repository]] for the current voting guidelines.
* Yes
* No
===== Patches and Tests =====
Links to proof of concept PR.
If there is no patch, make it clear who will create a patch, or whether a volunteer to help with implementation is needed.
===== Implementation =====
After the RFC is implemented, this section should contain:
- the version(s) it was merged into
- a link to the git commit(s)
- a link to the PHP manual entry for the feature
===== References =====
Links to external references, discussions, or RFCs.
===== Rejected Features =====
Keep this updated with features that were discussed on the mail lists.
===== Changelog =====
If there are major changes to the initial proposal, please include a short summary with a date or a link to the mailing list announcement here, as not everyone has access to the wikis' version history.