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

View other answers to this thread

Learn Something New Everyday,
Connect With The Best Developers!

Sign Up Now!

& 500k+ others use Hashnode actively.

Joe Clark's photo

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".

Mohammad Daud Ibrahim's photo

The Measure of a Man is What He Does with Power.

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!

Want to read more?

Browse featured discussions

© 2020 · Hashnode