开发者

Edit protected member in php

开发者 https://www.devze.com 2023-02-05 00:37 出处:网络
I have code similar to the following: class ModuleRaceRegistration extends Module { protected $strTemplate = \"template\";

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
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消