function bmethod() { $this->aprop = "the current instance"; aclass::aclass(); aclass::amethod(); // We want to disagree with PHP in this case. // notparent::nmethod(); }
up here <?php class aclass { var $exit = 1; function hi() { if ($this->exit) { exit; } else { print "sucked"; } } } $a = new aclass(); $a->hi(); ?> down here
function afunc() { //return parent::afunc(); $a = parent::afunc(); return $a; }
if ($numargs >= 2) { echo "1Second argument is: " . func_get_arg(1) . "<br />\n"; } $arg_list = func_get_args(); for ($i = 0; $i < $numargs; $i++) { echo "1Argument {$i} is: " . $arg_list[$i] . "<br />\n"; } } function afun_with_args($a) { $numargs = func_num_args(); echo "2Number of arguments: {$numargs}<br />\n"; if ($numargs >= 2) { echo "2Second argument is: " . func_get_arg(1) . "<br />\n"; } $arg_list = func_get_args(); for ($i = 0; $i < $numargs; $i++) { echo "2Argument {$i} is: " . $arg_list[$i] . "<br />\n"; } } } aclass::afun(1, 2); $a = new aclass(); $a->afun(88, 89, 90, 91); aclass::afun_with_args(1, 2); $a = new aclass(); $a->afun_with_args(88, 89, 90, 91); ?>
0000734 parse error on empty conditional block <?php class aclass { var $SfFilter; function afun($autoFilter) { if ($autoFilter) { // try to guess some filters to add based on it's name // EMAIL // FIXME - removed for now (weyrick) // if (eregi('email',$this->getName())) // $this->setSfFilter('email'); } } function setSfFilter($filter) { $this->SfFilter = $filter; } function getName() { return "foo"; } } $aninstance = new aclass(); $aninstance->afun(false); echo "{$aninstance->SfFilter}\n"; $aninstance->afun(true); echo "{$aninstance->SfFilter}\n";
<?php class aclass { function afunc($meep, $blah = '', $fnord) { var_dump($meep); var_dump($blah); var_dump($fnord); } } $a = new aclass(); $a->afunc('meep', 'hello'); $a->afunc('meep', 'hello', true);
0001017 need static variables in class methods in interpreter <?php class aclass { function amethod() { static $foo; return $foo++; } } print aclass::amethod() . "\n"; print aclass::amethod() . "\n"; print aclass::amethod() . "\n"; $anobj = new aclass(); print $anobj->amethod() . "\n"; print $anobj->amethod() . "\n"; print $anobj->amethod() . "\n";
{ $var =& new bclass($i, $this); $this->hash[$i] =& $var; return $var; } } class bclass { var $id; var $parent; function bclass($id, &$parent) { $this->id = $id; $this->parent =& $parent; } } $m = new aclass(); $a =& $m->afunc(1); $b =& $m->afunc(2); $c =& $m->afunc(3); $b->id = 10; $b->parent->hash[] = 'hello'; print_r($m); print_r($a); print_r($b); print_r($c); echo "\n\n and now, var_dump \n\n"; var_dump($m); var_dump($a); var_dump($b); var_dump($c);
<?php class aclass { var $blah = 'ho'; function unsetit() { var_dump($this->blah); unset($this->blah); var_dump($this->blah); } } $a = new aclass(); $a->unsetit();
0001345 parse error on class with method 'string' <?php class aclass { function string($string) { echo "your silly string was {$string}\n"; } } $a = new aclass(); $a->string('a phony phalacy'); ?>
<?php class aclass { var $avar; var $bvar; function afunc() { $a = array(1, 2, 3, 4, 5); foreach ($a as $this->avar) { echo "working with {$this->avar}\n"; } foreach ($a as $k => $this->avar) { echo "working with {$k} and {$this->avar}\n"; } foreach ($a as $this->avar => $v) { echo "working with {$v} and {$this->avar}\n"; } foreach ($a as $this->avar => $this->bvar) { echo "working with {$this->bvar} and {$this->avar}\n"; } var_dump($this->avar); } } $a = new aclass(); $a->afunc();
function __construct() { print "Constructor of bclass called\n"; parent::aclass(); parent::__construct(); }
0001024 unable to assign a reference to class property hash if the key doesn't already exist <?php class bclass { var $str = 'hi there'; } class aclass { var $directive = array(); function runit($a) { $b =& new bclass(); // uncomment this and it works //$this->directive['obj'][$a] = array(); $this->directive['obj'][$a] =& $b; } } $a = new aclass(); $a->runit('akey'); echo $a->directive['obj']['akey']->str;