Reputation: 433
Why is this line of code:
$this->plugins_dir[0] = SMARTY_DIR . 'plugins';
causing this error?
ERRNO: 8
TEXT: Indirect modification of overloaded property Page::$plugins_dir has no effect
By the way, the line of code is inside the constructor of a class named 'Page'.
I am working with PHP and PostgreSQL, but am not too experienced. I am stuck with this problem for few hours now, can't find the reason.
Upvotes: 3
Views: 4860
Reputation: 97718
What PHP is trying to tell you is that the property ->plugins_dir
doesn't really exist, but a magic __get()
function has been written that will return a value if you read from it. Assigning a variable directly to it might also work (if there is a corresponding __set()
) but you cannot modify it, since it is actually a function return value. You are effectively trying to say $this->__get('plugins_dir')[0] = 'foo'
, which doesn't mean anything.
However, looking at the relevant Smarty documentation, we can see what the correct solution is:
Note: As of Smarty 3.1 the attribute $plugins_dir is no longer accessible directly. Use getPluginsDir(), setPluginsDir() and addPluginsDir() instead.
So your code should actually use the pattern of one of the examples on the doc page for addPluginsDir(), such as:
$this->setPluginsDir( SMARTY_DIR . 'plugins' )
->addPluginsDir( '/some/other/source/of/plugins' );
Upvotes: 8
Reputation: 8872
I think this is the right way
$this->plugins_dir = SMARTY_DIR . 'plugins';
Upvotes: 0