Bug #80914 [Com]: function_exists is now case-sensitive for aliases
Edit report at https://bugs.php.net/bug.php?id=80914&edit=1
ID: 80914
Comment by: rowan dot collins at gmail dot com
Reported by: chris at vendiadvertising dot com
Summary: function_exists is now case-sensitive for aliases
Status: Open
Type: Bug
Package: *General Issues
Operating System: All
PHP Version: 8.0.3
Block user comment: N
Private report: N
New Comment:
There's actually something a lot weirder going on here.
Firstly, looking closely at the source, it seems that internally, getdir() is the *real* name of the
function, and dir() is the alias.
Secondly, there is no case-sensitivity change, and function_exists() was telling the truth, getdir()
really *didn't* exist on older versions of PHP: https://3v4l.org/dCpeh
It seems that this function had been there for years as some kind of ghost, and a change in PHP 8
brought it to life.
Previous Comments:
------------------------------------------------------------------------
[2021-03-29 17:54:25] chris at vendiadvertising dot com
I went through all 25 aliases listed in https://github.com/php/php-src/blob/master/ext/standard/basic_functions.stub.php
and it seems that getdir is the only only that is not listed in the PHP docs, so I'm fine
reclassifying this as a documentation update for that specific function.
I do still think, however, with how many aliases exist in PHP that this could still be a problem for
future upgraders.
------------------------------------------------------------------------
[2021-03-29 15:20:33] chris at vendiadvertising dot com
I absolutely agree that writing a function with the same name as a built-in but with different case
is asking for trouble. But is there a list of aliases somewhere to help someone troubleshoot this?
Looking at getdir specifically, searching the manual doesn't provide anything, and it is not
listed as an alias for dir. Maybe this is just a documentation bug then?
------------------------------------------------------------------------
[2021-03-29 15:13:16] egegeg dot egeez at fff dot ff
functions in php are generally case-insensitive and every place where they are not is and was a bug
by definition - so this is a bugfix and not a bug
writing plain functions without a prefix is bad coding style anyways because you never know if a
future version brings a native function with the same name but different semantics
calling a function identical as a builtin but with different case is asking for troubles no matter
what
------------------------------------------------------------------------
[2021-03-29 14:45:59] chris at vendiadvertising dot com
Description:
------------
Prior to PHP 8, a function could use the same name as a built-in function's alias as long as it
changed the case. For example, the built-in function dir has an internal alias of getdir, and
user-land code could create a function called getDir without issue. As of PHP 8, doing so will raise
a Fatal error: Cannot redeclare xyz.
https://3v4l.org/hdHSS
This was originally noted on SO https://stackoverflow.com/q/66854655/231316
It appears that Bug #79382 (Cannot redeclare disabled function) was fixed in https://github.com/php/php-src/commit/53eee290b6f5ca531aef19885a392c939013ce36.
That fix uses a simple lower-case lookup of the provided function's name.
To be clear, overriding a built-in function, alias or not, is probably not a good idea, and I
don't know if this should be fixed. But it is an unexpected breaking change for legacy code and
it should at least be documented.
Test script:
---------------
var_dump(function_exists('getDir'));
Expected result:
----------------
In PHP prior to 8, the check returned false.
Actual result:
--------------
Starting with PHP 8 this returns true
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80914&edit=1
Thread (8 messages)