I remember reading this code somewhere:
<?php
class test {
public $foo = 6, $bar;
}
$a = new test();
echo $a->foo; //6
echo $a->bar; //no output
What does the comma do in public $foo = 6, $bar;? Why does my IDE give me error when I remove public? I do find out that $bar is declared by doing so, but I don’t think that’s the sole reason why you code it this way though.
The comma is functionally the same as:
Basically, it just means declare another public variable. If you remove public, you’re no longer declaring a public variable, so your IDE complains. The reason people code that way is to save space. It’s just shorthand for a longer form.