I am working on some legacy code at the moment and stumbled across a weird class/function call that php.net doesn’t seem to explain and I’ve never seen before:
if(security::instance()->check_client()) {
There is a class security, and there are functions named instance and check_client inside that class. But this seems to call two functions in one statement and pass the one to the other, or at least thats what the outcome suggests.
Can someone clarify this one for me?
This is a classical implementation of the singleton pattern
I suppose your class
securitylooks like this :What it does is that the static method instance returns an instance of the class security; Which mean that
security::instance() instanceof security === trueThat’s why you can chain the call to the check_client() method as in your exemple
This is similar to