note 47121 added to language.oop5.autoload

From: Date: Wed, 03 Nov 2004 20:26:46 +0000
Subject: note 47121 added to language.oop5.autoload
Groups: php.notes 
Request: Send a blank email to php-notes+get-79564@lists.php.net to get a copy of this message
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); ?> ---- Manual Page -- http://www.php.net/manual/en/language.oop5.autoload.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+47121 Delete -- http://master.php.net/manage/user-notes.php?action=delete+47121&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47121&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47121&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47121&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47121&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47121&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+47121&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#79564) next »