[php-src] Issue #9631: PHP Namespaces

From: Date: Wed, 28 Sep 2022 17:34:13 +0000
Subject: [php-src] Issue #9631: PHP Namespaces
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-242481@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/9631 Author: tbejot007 ### Description I have 2 files with the same class name: The Users.php have the following: class User { public string $name = ""; public function __construct() { $this->name = 'John Doe'; } public function echoName(){ return $this->name; } } <?php include('../class/Users.php'); include('../users/Users.php'); Resulted in this output: //No error was listed. But I expected this output instead: Error - cannot use the same class name //This is the solution to get the error <?php include('../class/Users1.php'); include('../users/Users2.php'); Reload the page gives the appropriate error - cannot use the same class name //Then using namespaces will fix this error Since the files are of different paths and in the global namespace I would expect the error to occur but it did not. Not sure why I have to name the files with different names to get the error which may cause a problem in instantiating a class. if you use: $user = new User(); then no error is shown. but is does load the second file class if you run echo $user->echoName(); Shouldn't an error occur with the files named the same name but in a different directory? ### PHP Version PHP 8.1 ### Operating System _No response_

« previous php.bugs (#242481) next »