Is it possible to create a PHP class that would act like this:
class Foo
{
function __construct($param)
{
if (!is_numeric($param))
{
// stop class
}
}
}
$a = new Foo(2);
$b = new Foo('test');
var_dump($a);
var_dump($b);
which will return
object(Foo)[1]
null
The only way I’m aware of to stop creating of a new object while not immediately terminating the script is to throw an exception:
Of course, you’d have to be sure and catch the exception in the calling code and handle the problem appropriately.