Ahora funciona... No sé era exactamente lo que estaba mal... pero me pareció más "económico" pasarle el $ExtensionName al método MergeExtensionsVars() para que de esa manera no tenga que recorrer todo el array $this->extensions_vars.
Hice el cambio y ahora sí funcionan las referencias (Ojo... funciona el ejemplo que puse anteriormente... aún no he generado un PDF.).
Aquí dejo el código de fpdfExtensionsHandler:Además he corregido los pequeños errores que reportó Cluster y alguno que otro que por ahí había.
Código PHP:
require_once('fpdf.php');
/**
* This class has as goal, allow to use different FPDF extensions. Its created to work under PHP4
*/
class FpdfExtensionsHandler
{
/**
* FPDF main object
* @var object class FPDF
* @final
* @access public
*/
var $fpdf = null;
/**
* save the variables of the FPDF class
* @var Array
* @final
* @access private
*/
var $fpdf_vars = array();
/**
* save references to the loaded extensions
* @var Array
* @final
* @access private
*/
var $extensions_references = array();
/**
* save the extensions vars
* @var Array
* @final
* @access private
*/
var $extensions_vars = array();
/**
* current FPDF extension
* @var Object
* @final
* @access private
*/
var $extension = null;
/**
* default directory to search the extensions
* @var String
* @final
* @accesss private
*/
var $default_extensions_dir = './';
/**
* here can pass as many arguments as needed for the Fpdf constructor
* @return bool
* @param Mixed $FpdfConstructorArugment1
* @param Mixed $FpdfConstructorArugment2
* @param Mixed $FpdfConstructorArugmentN...
* @final
* @access public
*/
function FpdfExtensionsHandler()
{
if ( class_exists('FPDF') )
{
//getting FPDF vars
$this->fpdf_vars = get_class_vars('FPDF');
//create FPDF instance
$arguments = func_get_args();
$string_arguments = "";
foreach ( $arguments as $index => $argument )
{
$string_arguments .= "\$arguments[$index], ";
}
$string_arguments = substr($string_arguments,0,strlen($string_arguments) - 2);
$eval_code = "\$this->fpdf = new FPDF({$string_arguments});";
eval($eval_code);
return true;
}
else
{
die("Missing class FPDF!");
}
}
/**
* Try to load a new extension
* @return bool
* @param String $ExtensionName
* @param String $ExtensionDirectory
* @param Mixed $ExtensionConstructorArg1
* @param Mixed $ExtensionConstructorArg2
* @param Mixed $ExtensionConstructorArgN...
* @final
* @acces public
*/
function LoadExtension($ExtensionName, $ExtensionFile, $ExtensionDirectory = null)
{
$ExtensionName = (string)$ExtensionName;
$ExtensionDirectory = $ExtensionDirectory === null
? null
: (string)$ExtensionDirectory;
$class_file = $ExtensionDirectory === null
? $this->default_extensions_dir.$ExtensionFile
: $ExtensionDirectory.$ExtensionFile;
if ( file_exists($class_file) )
{
include_once $class_file;
if ( !class_exists($ExtensionName) )
{
die("Class '{$ExtensionName}' does not exists in file '{$class_file}'!");
}
else
{
//getting extension constructor arguments
$arguments = func_get_args();
$num_args = count($arguments);
$string_args = "";
for ( $i = 2; $i < $num_args; $i++ )
{
$string_args .= "\$arguments[$i], ";
}
$string_args = substr($string_args,0,strlen($string_args) - 2);
$eval_code = "\$this->extensions_references[\$ExtensionName] =& new \$ExtensionName($string_args);";
eval($eval_code);
if ( !is_subclass_of($this->extensions_references[$ExtensionName], 'FPDF') )
{
die("Class '{$ExtensionName}' is not a subclass of FPDF!");
}
else
{
$this->extensions_vars[$ExtensionName] = array();
$this->extensions_vars[$ExtensionName] = get_class_vars($ExtensionName);
$this->MergeExtensionsVars($ExtensionName);
return true;
}
}
}
else
{
die("Unable to open class file '{$class_file}'!");
}
}
/**
* Merge the loaded extensions variables, so every instance will edit the same variables
* @return bool
* @param void
* @final
* @acces private
*/
function MergeExtensionsVars($ExtensionName)
{
foreach ( $this->extensions_vars[$ExtensionName] as $variable_name => $variable_value )
{
if ( array_key_exists($variable_name, $this->fpdf_vars) )
{
$this->extensions_references[$ExtensionName]->$variable_name =& $this->fpdf->$variable_name;
}
}
}
/**
* Change the default directory for extensions
* @return bool
* @param String $DirectoryName
* @final
* @acces public
*/
function SetDefaultExtensionDir($DirectoryName)
{
$this->default_extensions_dir = (string)$DirectoryName;
return true;
}
/**
* Change the working extension
* @return bool
* @param String $ExtensionName
* @final
* @acces public
*/
function SetExtension($ExtensionName)
{
$ExtensionName = (string)$ExtensionName;
if ( array_key_exists($ExtensionName, $this->extensions_references) )
{
$this->extension =& $this->extensions_references[$ExtensionName];
return true;
}
{
die("Extension '{$ExtensionName}' does not has been loaded yet!");
}
}
}
Saludos