I've got a OOP script. One of my function is getObject($id)

So

$Car->getCar(34);
It goes to the database and get car ID 34 and populates the properties from this.

All works well.

However, if ID 34 doesn't exist I get errors. How should I manage this in the get car function or back on my main page

if (isset($Car->getCar(34))){
    
}

This doesn't work.

    What error are you getting and what does "doesn't work" mean, exactly? It could be that getCar() returns anything if a record associated with that ID isn't found - at that point your conditional would fail. Or it could be the underlying query is malformed and there an exception being thrown. We're gonna need a bit more information, I think.

      What @maxxd said, adding: if getCar() gives "errors" (whatever that means (bogus results, exceptions, error messages ,...)) for invalid inputs then I would expect that the interface being implemented would include some method for testing if a given input (such as 34) is valid.

        Write a Reply...