Edit protected member in php
I have code similar to the following:
class ModuleRaceRegistration extends Module
{
protected $strTemplate = "template";
protected function compile()
{
// this doesn't work
$this->strTemplate = "template2";
}
}
From within the c开发者_如何学Pythonompile
function I need to change the $strTemplate
member. How can I do this?
Is an error being returned? Also, this might not be the case but compile
is a protected
method so you can only call it from within the class. If you are trying to call it from outside of the class, then it would need to be public
.
Let me try
Example from manual
<?php
abstract class Base {
abstract protected function _test();
}
class Bar extends Base {
protected function _test() { }
public function TestFoo() {
$c = new Foo();
$c->_test();
}
}
class Foo extends Base {
protected function _test() {
echo 'Foo';
}
}
$bar = new Bar();
$bar->TestFoo(); // result: Foo
?>
精彩评论