What exactly is going on when you pass an object to an if, like this:
class TestClass {
...
}
$obj = new TestClass();
if($obj) { // what exactly is going on here ?
...
}
What exactly is going on when you pass an object to an if, like this:
class TestClass {
...
}
$obj = new TestClass();
if($obj) { // what exactly is going on here ?
...
}
Since your variable is an object, that will always be treated as true
- i.e. condition will always pass unless constructor of TestClass
will not instantiate object for some reason. You can see type-judging page to see how PHP handles type-casting (in this case, casting to boolean type)