note 126640 added to language.oop5.basic
| From: | johannes dot kingma at gmail dot com | Date: | Thu, 25 Nov 2021 11:29:12 +0000 |
| Subject: | note 126640 added to language.oop5.basic | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-217297@lists.php.net to get a copy of this message | ||
BEWARE!
Like Hayley Watson pointed out class names are not case sensitive.
<?php
class Foo{}
class foo{} // Fatal error: Cannot declare class foo, because the name is already in use
?>
As well as
<?php
class BAR{}
$bar = new Bar();
echo get_class($bar);
?>
Is perfectly fine and will return 'BAR'.
This has implications on autoloading classes though. The standard spl_autoload function will
strtolower the class name to cope with case in-sensitiveness and thus the class BAR can only be
found if the file name is bar.php (or another variety if an extension was registered with
spl_autoload_extensions(); ) not BAR.php for a case sensitive file and operating system like linux.
Windows file system is case sensitive but the OS is not and there for autoloading BAR.php will
work.
----
Server IP: 45.112.84.4
Probable Submitter: 45.112.85.242 (proxied: 83.97.87.182)
----
Manual Page -- https://php.net/manual/en/language.oop5.basic.php
Edit -- https://main.php.net/note/edit/126640
Del: integrated -- https://main.php.net/note/delete/126640/integrated
Del: useless -- https://main.php.net/note/delete/126640/useless
Del: bad code -- https://main.php.net/note/delete/126640/bad+code
Del: spam -- https://main.php.net/note/delete/126640/spam
Del: non-english -- https://main.php.net/note/delete/126640/non-english
Del: in docs -- https://main.php.net/note/delete/126640/in+docs
Del: other reasons-- https://main.php.net/note/delete/126640
Reject -- https://main.php.net/note/reject/126640
Search -- https://main.php.net/manage/user-notes.php