>I've created a class called university, it has a constructor which can >accept an id. If the id is sent during construction the constructor will >connect to a MySQL db to set all of the objects member variables to the >MySQl counterparts. > >I'd like to include some error notification so if I send it an id and >let's say that record doesn't exist in the db I get some notification and >can write a message out to log (or screen). But what is the best way to >do this? Any recommendations? Tutorials? URLs?
A short amount of testing shows that although you can't return a boolean value from the constructor function (the return value will be the object, and it will evaluate to true or false depending on the instance variables), you can do something like the following: class inconsequential { function inconsequential() { if(!$some_condition) $this = false; } } $s = new inconsequential(); printf("type of s: %s, value of s: %s\n", gettype($s), ($s ? 'true' : 'false')); // prints: "type of s: boolean, value of s: false" So, just have $this evaluate to false if some condition is not met, and you can then perform a check against the new constructor: if($o = new inconsequential()) { // do stuff } else { // oh no! } --------------------------------------------------------------------- michal migurski- contact info and pgp key: sf/ca http://mike.teczno.com/contact.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php