PHP Classes

PHP4 Issue

Recommend this page to a friend!

      Menu Builder  >  All threads  >  PHP4 Issue  >  (Un) Subscribe thread alerts  
Subject:PHP4 Issue
Summary:PHP4 Issue
Messages:4
Author:Sanjoy Ganguly
Date:2009-06-29 06:59:02
Update:2009-06-30 05:59:46
 

  1. PHP4 Issue   Reply   Report abuse  
Picture of Sanjoy Ganguly Sanjoy Ganguly - 2009-06-29 06:59:02
Hi,

Thanks for your great class. I want to use the files on my domain which is configured using PHP4. Can you please release a version which can be run using PHP4? Many Thanks.

  2. Re: PHP4 Issue   Reply   Report abuse  
Picture of Corey W. Corey W. - 2009-06-29 18:45:52 - In reply to message 1 from Sanjoy Ganguly
I can try, but it's going to be missing some nice features such as method chaining. Check back soon.

  3. Re: PHP4 Issue   Reply   Report abuse  
Picture of Corey W. Corey W. - 2009-06-29 19:49:34 - In reply to message 1 from Sanjoy Ganguly
I have added a PHP 4 compatible version of the classes. The only drawback of using PHP 4 with this class is the loss of method chaining, so you have to provide an array to the menu class.

  4. Re: PHP4 Issue   Reply   Report abuse  
Picture of Sanjoy Ganguly Sanjoy Ganguly - 2009-06-30 05:59:46 - In reply to message 3 from Corey W.
Hi,
Thanks for your quick reply.You are absolutely right about method chaining. I think you can chain the objects in PHP4 using the following ( You can try this ):-

<?php
function &chain(&$obj, $call) {
return call_chain($obj, explode('->',$call));
}
function &call_chain(&$obj, $stack) {
if ($stack) {
eval('$new_obj =& $obj->'.array_shift($stack).';');
return call_chain($new_obj, $stack);
} else {
return $obj;
}
}

?>

And here is a cheesy example:

<?php
class chainOne {
function &makeTwo() { return new chainTwo; }
}
class chainTwo {
function &makeThree($a,$b) { return new chainThree($b); }
}
class chainThree {
var $x;
function chainThree($x) { $this->x = $x; }
function &makeTest() { return new chainTest($this->x); }
}
class chainTest {
var $y;
function chainTest($y) { $this->y = $y; }
function &doIt($z) { return array('made it!',$this->y,$z); }
}

$GLOBALS['foo'] = 'baz';
$one =& new chainOne;
var_dump(
chain($one,
'makeTwo()->makeThree("foo","bar")->makeTest()->doIt($GLOBALS["foo"])'
));

?>

Many Thanks :)