I fell asleep while reading the Java Server Programming J2EE Edition again. But this time when I awoke I sat down and wrote some PHP code that is total gibberish, does not produce any errors and seems to be written in beer language.
class Foo
{
private $_stock = null;
private $_keg = null;
function __construct($name,$arg4)
{
$this->$name(' today');
$arg1 = ' has ale';
$arg2 = ' and pale ale';
$arg3 = ' and light beer';
$this->$name($arg1,$arg2);
$this->$name($arg1,$arg2,$arg3,$arg4);
}
function Variable()
{
$string = implode(func_get_args());
$this->Bar($string); // This calls the Bar() method
}
function Bar($string)
{
echo "This is Bar" . $string .'
';
}
}
$funcname = "Variable";
$foo = new Foo($funcname, ' tomorrow');
$foo->Bar(' is open');
$foo->$funcname(' has moved');
?>
I have no idea what problem I was trying to solve while asleep but it might be that I was just thirsty?
Happy Publishing!
After a couple of hours sleep and a glass of water the code gets to be a bit more clear. At least it is useful in this state. Though I have not yet come upon when it is useful.
< ?php
class Foo{
private $_stock = null;
private $_keg = null;
function __construct($name,$arg4){
$arg0 = ' is closed today';
$arg1 = ' has ale';
$arg2 = ' and pale ale';
$arg3 = ' and light beer';
switch ($name){
case 'cheers':
$this->check_access(’ is open today’);
$this->$name($arg1,$arg2,$arg4);
break;
case ‘warsaw_tavern’:
$this->check_access(’ has no beer today’);
$this->$name($arg1,$arg2,$arg3,$arg4);
break;
default:
$this->$name($arg0);
break;
}
}
function check_access(){
$string = implode(func_get_args());
$this->Bar($string); // This calls the Bar() method
}
function cheers(){
$string = implode(func_get_args());
$this->Bar($string); // This calls the Bar() method
}
function warsaw_tavern(){
$string = implode(func_get_args());
$this->Bar($string); // This calls the Bar() method
}
function Bar($string){
echo “This Bar” . $string .’
‘;
}
}
$funcname = “check_access”;
$foo = new Foo($funcname, ‘ is open tomorrow’);
$foo->$funcname(’ has moved’);
$foo->Bar(’ is open’);
$funcname = “cheers”;
$foo = new Foo($funcname, ‘ tomorrow at cheers’);
$funcname = “warsaw_tavern”;
$foo = new Foo($funcname, ‘ tomorrow at WT\’s’);
?>
the output
This Bar is closed today
This Bar has moved
This Bar is open
This Bar is open today
This Bar has ale and pale ale tomorrow at cheers
This Bar has no beer today
This Bar has ale and pale ale and light beer tomorrow at WT’s