Re: is_a fix for 5.4 and HEAD
| From: | Alan Knowles | Date: | Wed, 19 Oct 2011 01:18:41 +0000 |
| Subject: | Re: is_a fix for 5.4 and HEAD | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-55866@lists.php.net to get a copy of this message | ||
Supporting strings 'by default' in is_a() has the downside that it produces slightly unpredictable results. If you are accepting 'mixed' arguments, some of which may be strings, there is a slim chance that the string you accept will match the class or it's parent by accident.
Personally if I did not believe that the barrier for a BC change has to be alot higher than 'prettier or consistent API', i would have suggested that is_subclass_of should be changed to be 'consistent', and safer.
While the old justification for using is_a() over instanceof, has almost gone (it was the only way to write code that was portable to PHP4 & PHP5.*, except for the annoying depreciation message). I still consider is_a(), especially with negative testing slightly clearer to read than instanceof.
Regards
Alan
On Monday, October 17, 2011 09:22 PM, Jonathan Bond-Caron wrote:
On Sun Oct 16 06:59 PM, Stas Malyshev wrote:It definitely makes PHP worse by propagating inconsistent APIs.I created a patch against 5.4: https://bugs.php.net/patch-display.php?bug_id=55475&patch=is_a_5.4_alternati ve&revision=latest The patch changes the behavior to: is_a("ab", "b") // false is_a("ab", "b", true) // autoload "ab", autoload "b" -- false is_subclass_of("ab", "b") // false is_subclass_of("ab", "b", true) // autoload "ab", autoload "b" -- false Both class names can be "autoloaded" but not by default Thoughts?