Bug #52339 [Com]: SPL autoloader breaks class_exists()

2013-01-17 Thread php at maisqi dot com
Edit report at https://bugs.php.net/bug.php?id=52339&edit=1

 ID: 52339
 Comment by: php at maisqi dot com
 Reported by:dangerous dot ben at gmail dot com
 Summary:SPL autoloader breaks class_exists()
 Status: Re-Opened
 Type:   Bug
 Package:SPL related
 Operating System:   any (debian)
 PHP Version:5.3.3RC2
 Block user comment: N
 Private report: N

 New Comment:

This is clearly a bug. We're testing if a class exists not asserting it.
There's seam to be a patch for this. Any chance it will be accepted?


Previous Comments:

[2012-11-24 20:29:04] ciantic at oksidi dot com

Is this bug still happening in PHP5.4 and greater? I'm using 5.3.8.

If one uses class_exists it should never throw error, only true or false. It 
makes 
no sense otherwise. This is one of those where setting of some other 
application 
can totally broke functionality elsewhere. Should everyone using class_exists 
catch try LogicException too? I'd argue not.

Though the workaround (empty function for spl) is kind of nice, as dangerous 
dot 
ben mentioned.


[2012-08-08 16:18:39] kilbyc at bellsouth dot net

Even worse. The no arg register is inconsistent.



If the autoload stack is empty by the time the no arg registered is called, how 
can it function differently than if the autoload stack has been emptied by the 
time the no arg register is called?

This is nonsensical behavior, and manual for spl_autoload say nothing about it 
throwing. Let alone LogicException. I would have expected this to be a 
RuntimeException. As it depends on the specific environment it is run in as to 
whether or not spl_autoload will find something.


[2012-08-08 16:02:40] kilbyc at bellsouth dot net

PHP 5.3.8 (cli) (built: Aug 23 2011 11:50:20)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies




spl_autoload is inconsistent with itself.


[2012-03-16 22:02:29] pwolfenden at qualys dot com

Although I have not yet migrated to 5.3, I care about this bug because I'm 
using 
an autoload function (in 5.2) which contains some directory traversal logic and 
uses class_exists() to decide whether or not to keep looking. I need to do this 
because I'm in the scenario described by james (and so cannot assume that all 
the 
package files in my codebase follow my preferred naming convention), and I 
would 
much prefer class_exists() to continue to return false rather than having it 
throw 
a new Exception.


[2012-02-03 00:01:46] frozenf...@php.net

Re-opening, as there still exists the conflict of class_exists() generating an 
error when autoloading fails, which is a chicken and the egg sort of issue. If 
one wants to try autoloading if the class doesn't exist, but autoloading fails, 
it should be possible to recover from that failure.

My understanding of the underlying code is that it generates an error in this 
case. Perhaps it should generate an exception, which can be caught an handled.




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=52339


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=52339&edit=1


Bug #52339 [Com]: SPL autoloader breaks class_exists()

2012-11-24 Thread ciantic at oksidi dot com
Edit report at https://bugs.php.net/bug.php?id=52339&edit=1

 ID: 52339
 Comment by: ciantic at oksidi dot com
 Reported by:dangerous dot ben at gmail dot com
 Summary:SPL autoloader breaks class_exists()
 Status: Re-Opened
 Type:   Bug
 Package:SPL related
 Operating System:   any (debian)
 PHP Version:5.3.3RC2
 Block user comment: N
 Private report: N

 New Comment:

Is this bug still happening in PHP5.4 and greater? I'm using 5.3.8.

If one uses class_exists it should never throw error, only true or false. It 
makes 
no sense otherwise. This is one of those where setting of some other 
application 
can totally broke functionality elsewhere. Should everyone using class_exists 
catch try LogicException too? I'd argue not.

Though the workaround (empty function for spl) is kind of nice, as dangerous 
dot 
ben mentioned.


Previous Comments:

[2012-08-08 16:18:39] kilbyc at bellsouth dot net

Even worse. The no arg register is inconsistent.



If the autoload stack is empty by the time the no arg registered is called, how 
can it function differently than if the autoload stack has been emptied by the 
time the no arg register is called?

This is nonsensical behavior, and manual for spl_autoload say nothing about it 
throwing. Let alone LogicException. I would have expected this to be a 
RuntimeException. As it depends on the specific environment it is run in as to 
whether or not spl_autoload will find something.


[2012-08-08 16:02:40] kilbyc at bellsouth dot net

PHP 5.3.8 (cli) (built: Aug 23 2011 11:50:20)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies




spl_autoload is inconsistent with itself.


[2012-03-16 22:02:29] pwolfenden at qualys dot com

Although I have not yet migrated to 5.3, I care about this bug because I'm 
using 
an autoload function (in 5.2) which contains some directory traversal logic and 
uses class_exists() to decide whether or not to keep looking. I need to do this 
because I'm in the scenario described by james (and so cannot assume that all 
the 
package files in my codebase follow my preferred naming convention), and I 
would 
much prefer class_exists() to continue to return false rather than having it 
throw 
a new Exception.


[2012-02-03 00:01:46] frozenf...@php.net

Re-opening, as there still exists the conflict of class_exists() generating an 
error when autoloading fails, which is a chicken and the egg sort of issue. If 
one wants to try autoloading if the class doesn't exist, but autoloading fails, 
it should be possible to recover from that failure.

My understanding of the underlying code is that it generates an error in this 
case. Perhaps it should generate an exception, which can be caught an handled.


[2010-10-11 21:37:47] james at nearlysensical dot com

I 100% agree with dangerous dot ben. class_exists should return false if the 
class 
can't be autoloaded. Allowing it to do so would make it much easier to use an 
autoloader in contexts where you're interacting with an existing codebase that 
may 
not be so spl_autoload friendly. Bump.




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=52339


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=52339&edit=1


Bug #52339 [Com]: SPL autoloader breaks class_exists()

2012-08-08 Thread kilbyc at bellsouth dot net
Edit report at https://bugs.php.net/bug.php?id=52339&edit=1

 ID: 52339
 Comment by: kilbyc at bellsouth dot net
 Reported by:dangerous dot ben at gmail dot com
 Summary:SPL autoloader breaks class_exists()
 Status: Re-Opened
 Type:   Bug
 Package:SPL related
 Operating System:   any (debian)
 PHP Version:5.3.3RC2
 Block user comment: N
 Private report: N

 New Comment:

Even worse. The no arg register is inconsistent.



If the autoload stack is empty by the time the no arg registered is called, how 
can it function differently than if the autoload stack has been emptied by the 
time the no arg register is called?

This is nonsensical behavior, and manual for spl_autoload say nothing about it 
throwing. Let alone LogicException. I would have expected this to be a 
RuntimeException. As it depends on the specific environment it is run in as to 
whether or not spl_autoload will find something.


Previous Comments:

[2012-08-08 16:02:40] kilbyc at bellsouth dot net

PHP 5.3.8 (cli) (built: Aug 23 2011 11:50:20)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies




spl_autoload is inconsistent with itself.


[2012-03-16 22:02:29] pwolfenden at qualys dot com

Although I have not yet migrated to 5.3, I care about this bug because I'm 
using 
an autoload function (in 5.2) which contains some directory traversal logic and 
uses class_exists() to decide whether or not to keep looking. I need to do this 
because I'm in the scenario described by james (and so cannot assume that all 
the 
package files in my codebase follow my preferred naming convention), and I 
would 
much prefer class_exists() to continue to return false rather than having it 
throw 
a new Exception.


[2012-02-03 00:01:46] frozenf...@php.net

Re-opening, as there still exists the conflict of class_exists() generating an 
error when autoloading fails, which is a chicken and the egg sort of issue. If 
one wants to try autoloading if the class doesn't exist, but autoloading fails, 
it should be possible to recover from that failure.

My understanding of the underlying code is that it generates an error in this 
case. Perhaps it should generate an exception, which can be caught an handled.


[2010-10-11 21:37:47] james at nearlysensical dot com

I 100% agree with dangerous dot ben. class_exists should return false if the 
class 
can't be autoloaded. Allowing it to do so would make it much easier to use an 
autoloader in contexts where you're interacting with an existing codebase that 
may 
not be so spl_autoload friendly. Bump.


[2010-07-15 08:18:01] dangerous dot ben at gmail dot com

I beg to differ.  As you say, class_exists() attempts to autoload if there 
second param is true, but if autoloading fails it should simply return false as 
usual rather than throw an exception.  Otherwise it is rather useless.

The fact that this only occurs when there isn't another autoloader in the stack 
should make it clear that this is a bug.  For example, the following code does 
not throw an exception:

spl_autoload_register();
spl_autoload_register(function(){});
class_exists('foo\bar');




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=52339


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=52339&edit=1


Bug #52339 [Com]: SPL autoloader breaks class_exists()

2012-08-08 Thread kilbyc at bellsouth dot net
Edit report at https://bugs.php.net/bug.php?id=52339&edit=1

 ID: 52339
 Comment by: kilbyc at bellsouth dot net
 Reported by:dangerous dot ben at gmail dot com
 Summary:SPL autoloader breaks class_exists()
 Status: Re-Opened
 Type:   Bug
 Package:SPL related
 Operating System:   any (debian)
 PHP Version:5.3.3RC2
 Block user comment: N
 Private report: N

 New Comment:

PHP 5.3.8 (cli) (built: Aug 23 2011 11:50:20)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies




spl_autoload is inconsistent with itself.


Previous Comments:

[2012-03-16 22:02:29] pwolfenden at qualys dot com

Although I have not yet migrated to 5.3, I care about this bug because I'm 
using 
an autoload function (in 5.2) which contains some directory traversal logic and 
uses class_exists() to decide whether or not to keep looking. I need to do this 
because I'm in the scenario described by james (and so cannot assume that all 
the 
package files in my codebase follow my preferred naming convention), and I 
would 
much prefer class_exists() to continue to return false rather than having it 
throw 
a new Exception.


[2012-02-03 00:01:46] frozenf...@php.net

Re-opening, as there still exists the conflict of class_exists() generating an 
error when autoloading fails, which is a chicken and the egg sort of issue. If 
one wants to try autoloading if the class doesn't exist, but autoloading fails, 
it should be possible to recover from that failure.

My understanding of the underlying code is that it generates an error in this 
case. Perhaps it should generate an exception, which can be caught an handled.


[2010-10-11 21:37:47] james at nearlysensical dot com

I 100% agree with dangerous dot ben. class_exists should return false if the 
class 
can't be autoloaded. Allowing it to do so would make it much easier to use an 
autoloader in contexts where you're interacting with an existing codebase that 
may 
not be so spl_autoload friendly. Bump.


[2010-07-15 08:18:01] dangerous dot ben at gmail dot com

I beg to differ.  As you say, class_exists() attempts to autoload if there 
second param is true, but if autoloading fails it should simply return false as 
usual rather than throw an exception.  Otherwise it is rather useless.

The fact that this only occurs when there isn't another autoloader in the stack 
should make it clear that this is a bug.  For example, the following code does 
not throw an exception:

spl_autoload_register();
spl_autoload_register(function(){});
class_exists('foo\bar');


[2010-07-15 05:11:04] ka...@php.net

You are calling class_exists() with just a class name, which leaves the second 
parameter ($autoload) set to true, which then invokes SPL and throws the 
exception, so no bug here




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=52339


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=52339&edit=1


Bug #52339 [Com]: SPL autoloader breaks class_exists()

2012-03-16 Thread pwolfenden at qualys dot com
Edit report at https://bugs.php.net/bug.php?id=52339&edit=1

 ID: 52339
 Comment by: pwolfenden at qualys dot com
 Reported by:dangerous dot ben at gmail dot com
 Summary:SPL autoloader breaks class_exists()
 Status: Re-Opened
 Type:   Bug
 Package:SPL related
 Operating System:   any (debian)
 PHP Version:5.3.3RC2
 Block user comment: N
 Private report: N

 New Comment:

Although I have not yet migrated to 5.3, I care about this bug because I'm 
using 
an autoload function (in 5.2) which contains some directory traversal logic and 
uses class_exists() to decide whether or not to keep looking. I need to do this 
because I'm in the scenario described by james (and so cannot assume that all 
the 
package files in my codebase follow my preferred naming convention), and I 
would 
much prefer class_exists() to continue to return false rather than having it 
throw 
a new Exception.


Previous Comments:

[2012-02-03 00:01:46] frozenf...@php.net

Re-opening, as there still exists the conflict of class_exists() generating an 
error when autoloading fails, which is a chicken and the egg sort of issue. If 
one wants to try autoloading if the class doesn't exist, but autoloading fails, 
it should be possible to recover from that failure.

My understanding of the underlying code is that it generates an error in this 
case. Perhaps it should generate an exception, which can be caught an handled.


[2010-10-11 21:37:47] james at nearlysensical dot com

I 100% agree with dangerous dot ben. class_exists should return false if the 
class 
can't be autoloaded. Allowing it to do so would make it much easier to use an 
autoloader in contexts where you're interacting with an existing codebase that 
may 
not be so spl_autoload friendly. Bump.


[2010-07-15 08:18:01] dangerous dot ben at gmail dot com

I beg to differ.  As you say, class_exists() attempts to autoload if there 
second param is true, but if autoloading fails it should simply return false as 
usual rather than throw an exception.  Otherwise it is rather useless.

The fact that this only occurs when there isn't another autoloader in the stack 
should make it clear that this is a bug.  For example, the following code does 
not throw an exception:

spl_autoload_register();
spl_autoload_register(function(){});
class_exists('foo\bar');


[2010-07-15 05:11:04] ka...@php.net

You are calling class_exists() with just a class name, which leaves the second 
parameter ($autoload) set to true, which then invokes SPL and throws the 
exception, so no bug here


[2010-07-14 21:54:08] dangerous dot ben at gmail dot com

On further investigation, it appears that the error is meant to happen only if 
spl_autoload is called directly, and not via spl_autoload_call.  Unfortunately 
when spl_autoload is the only autoloader in the stack it gets called directly 
and spl_autoload_call doesn't get a look in.




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=52339


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=52339&edit=1


Bug #52339 [Com]: SPL autoloader breaks class_exists()

2010-10-11 Thread james at nearlysensical dot com
Edit report at http://bugs.php.net/bug.php?id=52339&edit=1

 ID: 52339
 Comment by: james at nearlysensical dot com
 Reported by:dangerous dot ben at gmail dot com
 Summary:SPL autoloader breaks class_exists()
 Status: Bogus
 Type:   Bug
 Package:SPL related
 Operating System:   any (debian)
 PHP Version:5.3.3RC2
 Block user comment: N

 New Comment:

I 100% agree with dangerous dot ben. class_exists should return false if
the class 

can't be autoloaded. Allowing it to do so would make it much easier to
use an 

autoloader in contexts where you're interacting with an existing
codebase that may 

not be so spl_autoload friendly. Bump.


Previous Comments:

[2010-07-15 08:18:01] dangerous dot ben at gmail dot com

I beg to differ.  As you say, class_exists() attempts to autoload if
there second param is true, but if autoloading fails it should simply
return false as usual rather than throw an exception.  Otherwise it is
rather useless.



The fact that this only occurs when there isn't another autoloader in
the stack should make it clear that this is a bug.  For example, the
following code does not throw an exception:



spl_autoload_register();

spl_autoload_register(function(){});

class_exists('foo\bar');


[2010-07-15 05:11:04] ka...@php.net

You are calling class_exists() with just a class name, which leaves the
second parameter ($autoload) set to true, which then invokes SPL and
throws the exception, so no bug here


[2010-07-14 21:54:08] dangerous dot ben at gmail dot com

On further investigation, it appears that the error is meant to happen
only if spl_autoload is called directly, and not via spl_autoload_call. 
Unfortunately when spl_autoload is the only autoloader in the stack it
gets called directly and spl_autoload_call doesn't get a look in.


[2010-07-14 21:31:46] dangerous dot ben at gmail dot com

Description:

Using PHP 5.3 from svn.



When SPL's default autoloader is the only loader in the stack it
triggers an error or throws an exception when it can't find a class. 
This means that you get an exception when calling class_exists() for a
class that doesn't exist.  This behaviour seems pointless anyway since
PHP will trigger its own fatal error if the class still doesn't exist
after attempting to autoload, so the attached patch simply removes it.





Test script:
---
spl_autoload_register();

class_exists('foo\bar');



Expected result:

No error



Actual result:
--
b...@arctor:~/src/php-5.3$ sapi/cli/php ~/code/cram/test.php 

PHP Fatal error:  Uncaught exception 'LogicException' with message
'Class foo\bar could not be loaded' in /home/ben/code/cram/test.php:4

Stack trace:

#0 [internal function]: spl_autoload('foo\bar')

#1 /home/ben/code/cram/test.php(4): class_exists('foo\bar')

#2 {main}

  thrown in /home/ben/code/cram/test.php on line 4








-- 
Edit this bug report at http://bugs.php.net/bug.php?id=52339&edit=1


Bug #52339 [Com]: SPL autoloader breaks class_exists()

2010-07-14 Thread dangerous dot ben at gmail dot com
Edit report at http://bugs.php.net/bug.php?id=52339&edit=1

 ID:   52339
 Comment by:   dangerous dot ben at gmail dot com
 Reported by:  dangerous dot ben at gmail dot com
 Summary:  SPL autoloader breaks class_exists()
 Status:   Bogus
 Type: Bug
 Package:  SPL related
 Operating System: any (debian)
 PHP Version:  5.3.3RC2

 New Comment:

I beg to differ.  As you say, class_exists() attempts to autoload if
there second param is true, but if autoloading fails it should simply
return false as usual rather than throw an exception.  Otherwise it is
rather useless.



The fact that this only occurs when there isn't another autoloader in
the stack should make it clear that this is a bug.  For example, the
following code does not throw an exception:



spl_autoload_register();

spl_autoload_register(function(){});

class_exists('foo\bar');


Previous Comments:

[2010-07-15 05:11:04] ka...@php.net

You are calling class_exists() with just a class name, which leaves the
second parameter ($autoload) set to true, which then invokes SPL and
throws the exception, so no bug here


[2010-07-14 21:54:08] dangerous dot ben at gmail dot com

On further investigation, it appears that the error is meant to happen
only if spl_autoload is called directly, and not via spl_autoload_call. 
Unfortunately when spl_autoload is the only autoloader in the stack it
gets called directly and spl_autoload_call doesn't get a look in.


[2010-07-14 21:31:46] dangerous dot ben at gmail dot com

Description:

Using PHP 5.3 from svn.



When SPL's default autoloader is the only loader in the stack it
triggers an error or throws an exception when it can't find a class. 
This means that you get an exception when calling class_exists() for a
class that doesn't exist.  This behaviour seems pointless anyway since
PHP will trigger its own fatal error if the class still doesn't exist
after attempting to autoload, so the attached patch simply removes it.





Test script:
---
spl_autoload_register();

class_exists('foo\bar');



Expected result:

No error



Actual result:
--
b...@arctor:~/src/php-5.3$ sapi/cli/php ~/code/cram/test.php 

PHP Fatal error:  Uncaught exception 'LogicException' with message
'Class foo\bar could not be loaded' in /home/ben/code/cram/test.php:4

Stack trace:

#0 [internal function]: spl_autoload('foo\bar')

#1 /home/ben/code/cram/test.php(4): class_exists('foo\bar')

#2 {main}

  thrown in /home/ben/code/cram/test.php on line 4








-- 
Edit this bug report at http://bugs.php.net/bug.php?id=52339&edit=1


Bug #52339 [Com]: SPL autoloader breaks class_exists()

2010-07-14 Thread dangerous dot ben at gmail dot com
Edit report at http://bugs.php.net/bug.php?id=52339&edit=1

 ID:   52339
 Comment by:   dangerous dot ben at gmail dot com
 Reported by:  dangerous dot ben at gmail dot com
 Summary:  SPL autoloader breaks class_exists()
 Status:   Open
 Type: Bug
 Package:  SPL related
 Operating System: any (debian)
 PHP Version:  5.3.3RC2

 New Comment:

On further investigation, it appears that the error is meant to happen
only if spl_autoload is called directly, and not via spl_autoload_call. 
Unfortunately when spl_autoload is the only autoloader in the stack it
gets called directly and spl_autoload_call doesn't get a look in.


Previous Comments:

[2010-07-14 21:31:46] dangerous dot ben at gmail dot com

Description:

Using PHP 5.3 from svn.



When SPL's default autoloader is the only loader in the stack it
triggers an error or throws an exception when it can't find a class. 
This means that you get an exception when calling class_exists() for a
class that doesn't exist.  This behaviour seems pointless anyway since
PHP will trigger its own fatal error if the class still doesn't exist
after attempting to autoload, so the attached patch simply removes it.





Test script:
---
spl_autoload_register();

class_exists('foo\bar');



Expected result:

No error



Actual result:
--
b...@arctor:~/src/php-5.3$ sapi/cli/php ~/code/cram/test.php 

PHP Fatal error:  Uncaught exception 'LogicException' with message
'Class foo\bar could not be loaded' in /home/ben/code/cram/test.php:4

Stack trace:

#0 [internal function]: spl_autoload('foo\bar')

#1 /home/ben/code/cram/test.php(4): class_exists('foo\bar')

#2 {main}

  thrown in /home/ben/code/cram/test.php on line 4








-- 
Edit this bug report at http://bugs.php.net/bug.php?id=52339&edit=1