In the following code, nonStatic() is not a static method. Even then I am able to access it without creating an object (in a static way). Could anyone please help me in understanding as this is not possible in other languages like Java?
<?php
class MyClass
{
function nonStatic() {
echo "This can be printed";
}
}
MyClass::nonStatic(); // This can be printed
Not sure, probably some PHP magic (it’s a bit like that sometimes), but you shouldn’t do it.
Read more here http://php.net/manual/en/language.oop5.static.php
They also show a similar example, but note:
Calling non-static methods statically generates an E_STRICT level warning meaning this magic ability may disappear in future versions. So don’t do it 🙂