note 80680 added to language.oop5.autoload

From: Date: Mon, 28 Jan 2008 19:59:15 +0000
Subject: note 80680 added to language.oop5.autoload
Groups: php.notes 
Request: Send a blank email to php-notes+get-135494@lists.php.net to get a copy of this message
I think i've found the holy grail.... use a wrapper function for the new statement, and all your problems are solved. <?php /** * PHP magic function, loads Objects automatically when needed. * * @param string class * @see http://php.net/manual/language.oop5.autoload.php */ function __autoload($class) { if (file_exists("./$class.php")) { require_once("./$class.php"); } else { throw new Exception("Unable to find required file to load $class"); } } /** * Wrapper for PHP new Class statement. * * @param string class * @param array arguments * @return object class or bool FALSE */ function new_class($class, array $arguments = array()) { try { class_exists($class); } catch(Exception $exception) { echo $exception->getMessage(); return FALSE; } return new $class($arguments); } ?> ---- Server IP: 89.248.170.58 Probable Submitter: 85.149.120.16 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.autoload.php Edit -- https://master.php.net/note/edit/80680 Del: integrated -- https://master.php.net/note/delete/80680/integrated Del: useless -- https://master.php.net/note/delete/80680/useless Del: bad code -- https://master.php.net/note/delete/80680/bad+code Del: spam -- https://master.php.net/note/delete/80680/spam Del: non-english -- https://master.php.net/note/delete/80680/non-english Del: in docs -- https://master.php.net/note/delete/80680/in+docs Del: other reasons-- https://master.php.net/note/delete/80680 Reject -- https://master.php.net/note/reject/80680 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#135494) next »