note 100378 added to function.spl-autoload-register

From: Date: Tue, 12 Oct 2010 13:17:26 +0000
Subject: note 100378 added to function.spl-autoload-register
Groups: php.notes 
Request: Send a blank email to php-notes+get-173157@lists.php.net to get a copy of this message
in reply to: a dot schaffhirt at sedna-soft dot de Autoloading namespaced classes without an explicit autoload function only works on windows (the namespace’s backslashes serve as directory separator). however any *nix file system requires the \ to / conversion. The PHP Standards Working Group has given an example, which should work in every environment: <?php function autoload($className) { $className = ltrim($className, '\\'); $fileName = ''; $namespace = ''; if ($lastNsPos = strripos($className, '\\')) { $namespace = substr($className, 0, $lastNsPos); $className = substr($className, $lastNsPos + 1); $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; } $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; require $fileName; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 84.183.7.247 ---- Manual Page -- http://www.php.net/manual/en/function.spl-autoload-register.php Edit -- https://master.php.net/note/edit/100378 Del: integrated -- https://master.php.net/note/delete/100378/integrated Del: useless -- https://master.php.net/note/delete/100378/useless Del: bad code -- https://master.php.net/note/delete/100378/bad+code Del: spam -- https://master.php.net/note/delete/100378/spam Del: non-english -- https://master.php.net/note/delete/100378/non-english Del: in docs -- https://master.php.net/note/delete/100378/in+docs Del: other reasons-- https://master.php.net/note/delete/100378 Reject -- https://master.php.net/note/reject/100378 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#173157) next »