PHP classes should normally be in a file by themselves. Static PHP methods can be called within PHP without instantiation of the class as below:
<?php
class TestClass
{
static function myStaticFunction()
{
return "The uninstantiated return value";
}
}
echo TestClass::myStaticFunction();
// echos "The uninstantiated return value"
It is easy to use a Javascript ajax call to a PHP script that instantiates a PHP class and runs a class method.
My question is: Is it possible to call a PHP static class method from Javascript using ajax thus eliminating the need for an intermediate PHP script or instantiation of the class, while not violating the PHP good practice of classes being in separate files all to themselves.
I tried putting the call to the PHP static method in the class constructor and got an error message. Putting all of the functionality in the constructor would also defeat the utility of the class for other purposes.
If this is possible please show how one would call a static PHP class method using ajax without using an intermediary script. If this has been answered before please provide a link to the answer before closing this question as I have not found an answer directly on point.
If this is impossible, why is it that PHP can call a static class method without instantiation, but Javascript cannot do the same via ajax?