To clarify:
- no I can't make this pure PHP5
- yes this code works in PHP 4.3.9.
I don't have any real world experience implementing or supporting PHP4 but I had to recently change my class so it supports both PHP4 and PHP5.
- Can anyone foresee any possible issues in regards to my implementation of the singleton method used here? I only want one instance of this class.
- I know I could completely get rid of the
__construct
method, should I? ( and move the function body of it to the Conf function ). - Could I have used
self
anywhere? I wasn't sure of its PHP4 support.
<?php
class Conf {
function Conf( $filename ) {
$this->__construct( $filename );
}
function __construct( $filename ) {
echo $filename;
}
function getInstance( $filename ) {
static $instance = null;
if ( $instance == null ) {
$instance = new Conf( $filename );
}
return $instance;
}
}
$x = Conf::getInstance( 'file.xml' );