Bug #80914 [Com]: function_exists is now case-sensitive for aliases

From: Date: Mon, 29 Mar 2021 15:13:16 +0000
Subject: Bug #80914 [Com]: function_exists is now case-sensitive for aliases
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-233041@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80914&edit=1

 ID:                 80914
 Comment by:         egegeg dot egeez at fff dot ff
 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:

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


Previous Comments:
------------------------------------------------------------------------
[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)

« previous php.bugs (#233041) next »