Re: include_once/__autoload/namespace emulation ...
- From: "Sean" <oreilly.sean@xxxxxxxxx>
- Date: 29 Nov 2005 06:21:29 -0800
Namespaces and PHP are certainly an issue, some of the things you wrote
I have never heard of before, like require_once being bugged.
Pear is a good example of how namespaces should be done but I would
suggest an even simpler solution.
Say you have a folder structure like:
>classes
>>XML
>>>Parser.inc.php
>>>Transformer.inc.php
>>DB
>>>Mysql.inc.php
>>FILE_SYSTEM
>>>File.inc.php
They you should have an auto load function like:
function __autoload( $class )
{
$load = strtolower( str_replace( "_", "/classes/", $class ) ) .
".inc.php";
if( file_exists( $load ) )
{
include_once( $load );
}
else
{
die( "Can't find a file for class: $class \n" );
}
}
Now you can have
$obj = new XML_Parser();
(example adapter from http://www.wiki.cc/php/Overload_autoload).
This makes things allot easier. The drawback is it is not php4
compatible.
.
- Follow-Ups:
- Re: include_once/__autoload/namespace emulation ...
- From: Kevin Newman
- Re: include_once/__autoload/namespace emulation ...
- References:
- include_once/__autoload/namespace emulation ...
- From: Kevin Newman
- include_once/__autoload/namespace emulation ...
- Prev by Date: Re: export flat file db into mysql?
- Next by Date: Re: Changes to php.ini not being read through
- Previous by thread: include_once/__autoload/namespace emulation ...
- Next by thread: Re: include_once/__autoload/namespace emulation ...
- Index(es):
Relevant Pages
|