I started to learn OO a few days back, I'm quite OK with procedural coding but obviously that is not enough and I want to become a well versed coder with a lot of experience and knowledge, so first thing to learn completely must be OO followed by the right design patterns I think.
Anyhow, I have one thing where I'm stuck which I don't quite follow...
Static variables... I understand that a static variable doesn't lose it's value even if the containing function is finished executing, and will keep it's value if the same function is executed again, and again etc etc.
But what I don't understand is what exactly can you now assign to a static variable? The manual and also countless question on stackoverflow state you can not assign an expression to a static variable.
So I read the PHP manual, to find out exactly what is considered an expression? The manuals answer is (and I quote):
"In PHP, almost anything you write is an expression. The simplest yet most accurate way to define an expression is "anything that has a value"."
"When you type "$a = 5", you're assigning '5' into $a. '5', obviously, has the value 5, or in other words '5' is an expression"
http://php.net/manual/en/language.expressions.php
Now when you read about variable scope in the manual, they have exactly this example:
function test()
{
static $a = 0;
echo $a;
$a++;
}
So, the manual about variable scopes says static $a = 0; is fine, while the manual about expressions says $a = 5, would be an expression. Which is basically the same thing, just a 0 instead of a 5...
So I'm a bit confused now.
What exactly is an expression now and what exactly can I or can I not assign to static variables? :)