Apologies if this is a very simple question, as the problem highlights itself as a compiler error. I'm a self taught PHP programmer, so I'm probably misunderstanding something from the object orientated side of things - but despite some googling, it's got me stumped as to how to get around it.
I came across the issue when I had to make some fixes to someone else's phpunit code. They had a protected array in a class with one of the key values set as XML text. However, I found that it needed to be converted to a SimpleXMLElement. So I tried converting using simplexml_load_string(). However, this just resulted in the syntax error:
PHP Parse error: syntax error, unexpected '(', expecting ')'
I didn't understand this, so I stripped down to a simple standalone example which replicates the problem:
<?php
class problemDemo
{
protected $Len = strlen('MY_TEXT');
}
?>
So can anyone explain why I can't set a protected variable value within a class using a function? Is there any alternative way to get around?
PS. Apologies for post subject - it should have said "CAN'T use a function when defining a protected class variable"!