David Murdoch
David Murdoch

Reputation: 89312

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 compile function I need to change the $strTemplate member. How can I do this?

Upvotes: 1

Views: 260

Answers (2)

Wasim Karani
Wasim Karani

Reputation: 8886

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

Upvotes: 0

Matt Lowden
Matt Lowden

Reputation: 2616

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.

Upvotes: 1

Related Questions