note 47121 deleted from language.oop5.autoload by nlopess

From: Date: Thu, 04 Nov 2004 19:27:47 +0000
Subject: note 47121 deleted from language.oop5.autoload by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-79631@lists.php.net to get a copy of this message
Note Submitter: cameron at cameron dot co dot nz ---- The __autoload function does NOT apply to extensions. For example: <?php /* This class file is saved as "sql.class.php" */ class sql { function __construct($sql) { $this->sql=$sql; $this->res=mysql_query($this->sql) or die ("Could not execute ".$this->sql." query."); $this->num_rows=mysql_num_rows($this->res); $this->row_array=mysql_fetch_array($this->res); } } class format_sql extends sql { function __construct($sql) { parent::__construct($sql); for($r=0;$r<$this->num_rows;$r++) { .... /*Format the data*/ } } } ?> Now we construct the calling functions. <?php function __autoload($class_name) { $class=$class_name.".class.php"; print $class; include_once($class); } $sql="select * from member"; new format_data($sql); /* This will NOT work. __autoload requires you to invoke the name of the file and by implication the name of the parent (after whom the file is named). Thus, this is required to invoke an extended class. */ new sql($sql); new format_sql($sql); ?>

« previous php.notes (#79631) next »