[phplib-users] Useful PHP5 data format
Brought to you by:
nhruby,
richardarcher
|
From: Lindsay H. <fmo...@fm...> - 2008-08-23 15:58:20
|
FWIW, here's the file layout I use for PHP5 sites. It's quite
convenient and allows me to incorporate whatever set of libs I want to
use, including legacy PHPlib, into a website. I have a couple of dozen
websites on the server.
My php.ini file specifies an auto_prepend
file, /var/www/localhost/prepend/fmp_prepend5.inc which contains the
following:
<?php
set_include_path($_SERVER['DOCUMENT_ROOT'] . "/fmplib" . PATH_SEPARATOR . get_include_path() . PATH_SEPARATOR . "/var/www/localhost/include");
@include_once($_SERVER['DOCUMENT_ROOT'] . "/fmplib/local.inc");
function __autoload($class_name) {
(@include_once "class.".$class_name.".inc") || (@include_once "class.".$class_name.".php");
}
?>
This does three things.
First, it defines a search path which includes a special library
directory off of the DocumentRoot for each virtual host (in my case,
fmplib/). This path element is followed by a global library directory
(in my case /var/www/localhost/include).
Second, it auto_includes a "local.inc" file from the virtual host
library directory. This is not related to PHPlib's local.inc. It's
somewhat the equivalent of PHPlib's $auto_init, but more transparent in
operation. This local.inc file can either be PHPlib's prepend.php file,
or can include prepend.php in addition to whatever other includes are
needed.
Third, it defines the PHP5 special __autoload() function so that any
attempt to instantiate a class causes PHP to attempt to find and include
the proper file containing the class. The only drawback here is that
this happens silently, so that not only are any errors in the include
operation suppressed, but any errors generated by the included code are
also suppressed. For debugging purposes, I generally explicitly include
class files in code (sans the "@") which supercedes the __autoload().
PHPlib's prepend.php would be simplified considerably if some thought
were given to filenames, and the classes therein were properly allocated
so as to take advantage of PHP5's __autoload feature.
--
Lindsay Haisley | "In an open world, | PGP public key
FMP Computer Services | who needs Windows | available at
512-259-1190 | or Gates" | http://pubkeys.fmp.com
http://www.fmp.com | |
|