|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-11-01 20:48 UTC] yohgaki@php.net
[2016-11-01 20:56 UTC] yohgaki@php.net
[2016-11-01 21:17 UTC] yohgaki@php.net
[2016-11-08 22:45 UTC] oliver dot saunders at gmail dot com
[2021-07-30 12:38 UTC] cmb@php.net
-Status: Open
+Status: Wont fix
-Assigned To:
+Assigned To: cmb
[2021-07-30 12:38 UTC] cmb@php.net
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 21:00:01 2025 UTC |
Description: ------------ (I choose "Reflection related" as "Package affected" because that was the closest thing I could see but this really more of a core language thing.) PHP already has a function to create class aliases via class_alias(): class Foo { } class_alias('Foo', 'Bar'); $x = new Bar; var_dump($x); // -> object(Foo)#1 (0) { } despite the relative ease with which a lot of classes can be aliased using inheritance anyway: class Foo { } class Bar extends Foo { } $x = new Bar; // has all features of Foo (Granted inheritance isn't exactly the same as aliasing but functionally equivalent in many cases.) By comparison creating two functions of the same name requires you to repeat the argument list and can potentially make mistakes in the function body that would not be caught until the secondary function is called: function addThree($a, $b, $c) { return $a + $b + $c; } function add3($a, $b, $c) { return addThee($a, $b, $c); // mistake not caught until add3 called } A predefined function such as `function_alias(string $orig, string $alias)` would simplify the above to: function addThree($a, $b, $c) { return $a + $b + $c; } function_alias('addThree', 'add3'); and allow errors to be caught earlier: function_alias('addThee', 'add3'); // trigger error immediately Additionally if the argument list of addThree were to change with `function_alias()` it only has to be changed in one place instead of 2. I program in PHP using a modern functional style and make liberal use of freestanding functions i.e. not class members. To be able to simply alias them would be very useful and convenient to anyone who likes to program in this style which I believe will become more popular.