Created
February 6, 2024 11:53
-
-
Save sirreal/3d4174b57df87b972e4705705024d672 to your computer and use it in GitHub Desktop.
Demo php clase name collision problems
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo "Running test from: " . PHP_VERSION . PHP_EOL; | |
// Comment this line to trigger other errors | |
require_once __DIR__ . '/unconditional.php'; | |
require_once __DIR__ . '/b.php'; | |
require_once __DIR__ . '/c.php'; | |
$a = new Already_Defined(); | |
// Uncommenting the top require_once would cause an error here | |
require_once __DIR__ . '/unconditional.php'; | |
try { | |
// Uncommenting this line would cause fatal errors | |
// class Already_Defined {}; | |
// Uncommenting the top require_once would cause an error here | |
require_once __DIR__ . '/unconditional.php'; | |
} catch ( Error $e ) { | |
echo "Creating the class unconditionally would error." . PHP_EOL; | |
var_dump($e); | |
} | |
echo "Ran to completion, created class instance: " . get_class($a) . PHP_EOL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (class_exists('Already_Defined') ) { | |
return; | |
} | |
class Already_Defined { | |
public function __construct() { | |
echo 'Initialized from ' . __FILE__ . PHP_EOL; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (class_exists('Already_Defined') ) { | |
return; | |
} | |
class Already_Defined { | |
public function __construct() { | |
echo 'Initialized from ' . __FILE__ . PHP_EOL; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM php:7.0-alpine | |
COPY . . | |
ENTRYPOINT ["php", "a.php"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM php:8.3-alpine | |
COPY . . | |
ENTRYPOINT ["php", "a.php"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker build --quiet --file ./Dockerfile.php7 --tag demo-php-70 . | |
docker build --quiet --file ./Dockerfile.php8 --tag demo-php-83 . | |
docker run demo-php-70 || echo "Errored." | |
echo "---" | |
docker run demo-php-83 || echo "Errored." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Already_Defined { | |
public function __construct() { | |
echo 'Initialized from ' . __FILE__ . PHP_EOL; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment