note 50803 added to function.require-once

From: Date: Thu, 10 Mar 2005 13:00:36 +0000
Subject: note 50803 added to function.require-once
Groups: php.notes 
Request: Send a blank email to php-notes+get-86201@lists.php.net to get a copy of this message
When you feel the need for a require_once_wildcard function, here's the solution: <?php // /var/www/app/system/include.inc.php function require_once_wildcard($wildcard, $__FILE__) { preg_match("/^(.+)\/[^\/]+$/", $__FILE__, $matches); $ls = ls $matches[1]/$wildcard; $ls = explode("\n", $ls); array_pop($ls); // remove empty line ls always prints foreach ($ls as $inc) { require_once($inc); } } ?> The $__FILE__ variable should be filled with the special PHP construct __FILE__: <?php // /var/www/app/classes.inc.php require_once('system/include.inc.php'); require_once_wildcard("classes/*.inc.php", __FILE__); ?> The (*.inc.php) files inside the directory classes are automagically included using require_once_wildcard. This solution may not be as useful when using PHP5 in combination with classes and the autoload feature. -- Jaap Taal ---- Manual Page -- http://www.php.net/manual/en/function.require-once.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+50803 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50803&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50803&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50803&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50803&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50803&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+50803&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#86201) next »