It's time to ditch Medium for good! 🌈⚡️

Introducing Devblog by Hashnode. Blog on your domain for FREE. Highly customizable and optimized for developers.

Learn more

PHP allows access to non-static methods using ClassName:: But Why does it throw error when accessing non-static properties using ClassName::?


From what I've read, PHP 4 didn't have the static keyword in function declarations, but still allowed you to call a method using the :: static operator. It was kept for backward compatibility reasons in PHP 5 and up and in PHP 7+ is deprecated. I started with PHP 5.4, so never encountered this quirk. To me, it seems like a bug. But it is indeed a "feature".

AARGH! as a Novice I find this very confusing. I guess I've to stop tiring myself over this and consider it as " This is how it works in PHP ".
Your answer sounds logical, helpful indeed Thanks!

Reply to this…

(3 answers) Take me to the question