phptools-docs
phptools-docs copied to clipboard
No warning for calling protected function from unrelated class
There's no warning whatsoever for calling a protected method from an unrelated class. In reality this will throw an error at runtime.
Example code:
<?php
class Test1 {
protected function doWhatever() {
}
}
class Test2 {
public function doSomething() {
$test = new Test1();
$test->doWhatever(); // <<<<<<<<<<<<<<<<<< this should trigger a warning
}
}
$test2 = new Test2();
$test2->doSomething();
https://3v4l.org/8iUK4
Fatal error: Uncaught Error: Call to protected method Test1::doWhatever() from scope Test2 in /tmp/preview:12
Stack trace:
#0 /tmp/preview(17): Test2->doSomething()
#1 {main}
thrown in /tmp/preview on line 12