php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34109 __autoload interupting normal "code flow"
Submitted: 2005-08-12 22:01 UTC Modified: 2005-08-12 22:41 UTC
From: info at tphnet dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.0.4 OS: Windows XP SP2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: info at tphnet dot com
New email:
PHP Version: OS:

 

 [2005-08-12 22:01 UTC] info at tphnet dot com
Description:
------------
I've been toying around a bit with the __autoload() functionallity and along the way found some strange behaviour.
I'm not entirely sure it's bug, but it's at least not working as I would expect it.

I created a system which allows classes to register themselfs with a "registration object" when loaded. When registering, some checks are executed to (for example) see if the class that's being registered is of the right type.
Below is a very simplified version of my script, it serves no purpose but to show my problem.

Reproduce code:
---------------
Index.php
<?php

function __autoload($class){

	include($class . '.php');}

$Class = new Class2();

?>

Class1.php
<?php

class Class1{

	public static function CheckClass2(){
	
		is_subclass_of('Class2', 'Class1');}}

?>

Class2.php
<?php

Class1::CheckClass2();

class Class2 extends Class1{}

?>

Expected result:
----------------
When running Index.php, a blank page should be displayed.

Actual result:
--------------
When running Index.php, the following error appears:

Warning: Unknown class passed as parameter in Class1.php on line 7

I can only assume that by using the __autload() function the normal flow of code processing is changed in some way.
Class2 seems not to be defined by the time the CheckClass2() method is called, even though Class2.php should've been included before Class1.php (where this method is located).

When I manually include both files in Index.php the code works fine, same goes for placing the call to CheckClass2() below the definition of Class2.

Again, I'm not sure whether this is a bug or just "the way it works". It's although not what I would expect to happen...

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-08-12 22:41 UTC] sniper@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 20 03:01:32 2024 UTC