Jump to content

whitburn

New Members
  • Posts

    2
  • Joined

  • Last visited

Everything posted by whitburn

  1. Thanks, that explains my misunderstanding I'll give it a try.
  2. 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"!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.