I understand that there are two ways to access a PHP class – “::” and “->”. Sometime one seems to work for me, while the other doesn’t, and I don’t understand why.
What are the benefits of each, and what is the right situation to use either?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Simply put,
::is for class-level properties, and->is for object-level properties.If the property belongs to the class, use
::If the property belongs to an instance of the class, use
->