So yeah, I was wondering if you can do it..
class Ping
{
function __construct()
{
return self::ping();
}
private static function ping()
{
if ((1 - 1) == 0)
{
return false;
}
else
{
return true;
}
}
}
And usage is:
Class ServerHandler
{
public function check()
{
if (new Ping())
{
ECHO 1;
}
else
{
echo 2;
}
}
}
So basically, it doesn't work. My website is echoing '1' instead of '2' cause false must return '2'.
Basically, I want to check if it returns true or false.
For example, a boolean variable can do that:
if (variable)
{
then...
}
But why can't a class do that? I mean I am returning the boolean, using the constructor? Why doesn't it work?
var_dump(new Ping());Will show you exactly what is returned, but the OOP correct way would be$ping = new Ping(); $ping->ping();asnew Ping();creates an instance of the ping class rather than just returning true or false.