Answer the question
In order to leave comments, you need to log in
Why is there an error when an optional access modifier is missing in a PHP class?
Hello!
Here is a quote from the documentation :
Class methods must be defined with the public, private, or protected modifiers. Methods where there is no modifier definition are defined as public.
class A{
$attribute = 5; //без модификатора доступа public (который по умолчанию)
}
Parse error: syntax error, unexpected '$attribute' (T_VARIABLE), expecting function (T_FUNCTION) in C:\OpenServer\domains\comet\php.php on line 4
class A{
public $attribute = 5; //без модификатора доступа public (который по умолчанию)
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question