Bug #79022 [Com]: class_exists returns True for classes that are not ready to be used
Edit report at https://bugs.php.net/bug.php?id=79022&edit=1
ID: 79022
Comment by: raj0chaturvedi at gmail dot com
Reported by: mech at themech dot net
Summary: class_exists returns True for classes that are not
ready to be used
Status: Closed
Type: Bug
Package: *General Issues
Operating System: Linux
PHP Version: 7.4.1
Block user comment: N
Private report: N
New Comment:
> gc '.\test script.php'
<?php
function my_autoloader($class) {
if (class_exists('Foo', False)) {
new Foo();
}
if ($class == 'Foo' or $class == 'Bar') {
include_once "classes/$class.php";
}
}
spl_autoload_register('my_autoloader');
new Foo();
echo "end";
---
---
> gci | ft FullName
FullName
--------
D:\repro bug 79022\classes
D:\repro bug 79022\test script.php
---
---
> gc .\classes\Bar.php
<?php
class Bar {}
> gc .\classes\Foo.php
>
<?php
include_once "Bar.php";
class Foo extends Bar {}
---
---
works for me on Windows 10 1909. with above code and files.
tested by typing
>php.exe "test script.php"
and
>php.exe -f "test script.php"
> php -v
PHP 7.4.2 (cli) (built: Jan 21 2020 17:53:48) ( ZTS Visual C++ 2017 x86 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
about comment formatting: I don't know how to format it. See https://pastebin.com/QHzw60Dg for colored output. the paste
expires in 364 days. to see raw paste content https://pastebin.com/raw/QHzw60Dg
---
---
aside:
To repeat a message I thought was unexpected uncomment the include_once "Bar.php" line in
Foo.php file. Then type
> php .\classes\Foo.php
PHP Fatal error: Uncaught Error: Class 'Bar' not found in D:\repro bug
79022\classes\Foo.php:4
Stack trace:
#0 {main}
thrown in D:\repro bug 79022\classes\Foo.php on line 4
Fatal error: Uncaught Error: Class 'Bar' not found in D:\repro bug 79022\classes\Foo.php:4
Stack trace:
#0 {main}
thrown in D:\repro bug 79022\classes\Foo.php on line 4
It is a bit weird that the exact same error is printed twice. And now, more weird stuff, note the
include-once line is commented.
> php -f '.\test script.php'
end
> php.exe -f .\classes\Bar.php
> php.exe -f .\classes\Bar.php
I think it's weird that the first command prints end and nothing else. When compared to how
'php -f Foo.php' is handled.
Previous Comments:
------------------------------------------------------------------------
[2020-02-11 10:07:54] raj0chaturvedi at gmail dot com
Related To: Bug #79022
------------------------------------------------------------------------
[2020-02-11 10:07:54] raj0chaturvedi at gmail dot com
Related To: Bug #79022
------------------------------------------------------------------------
[2020-02-11 10:07:54] raj0chaturvedi at gmail dot com
Related To: Bug #79022
------------------------------------------------------------------------
[2020-02-11 10:07:54] raj0chaturvedi at gmail dot com
Related To: Bug #79022
------------------------------------------------------------------------
[2020-02-11 10:07:54] raj0chaturvedi at gmail dot com
Related To: Bug #79022
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=79022
--
Edit this bug report at https://bugs.php.net/bug.php?id=79022&edit=1
Thread (3 messages)