Voting

: min(seven, four)?
(Example: nine)

The Note You're Voting On

backnot
3 years ago
In the above example (#3) in order to make it work, you can change the child's method from 'private' to 'protected' (or public) and it will be called through 'static'.

<?php
class A {
private function
foo() {
echo
"success!\n";
}
public function
test() {
$this->foo();
static::
foo();
}
}

class
B extends A {
/* foo() will be copied to B, hence its scope will still be A and
* the call be successful */
}

class
C extends A {
protected function
foo() { //note the change here
echo 'hello world!';
}
}

$b = new B();
$b->test();
$c = new C();
$c->test(); // 'success' 'hello world'
?>

<< Back to user notes page

To Top