i'm creating a couple classes to control user authentication and navigation in a website...
one class' __construct() receives 2 arguments as parameters, validates them and if they are both valid stores them and initializes the rest of the class. if validation fails, i made it return NULL in order to try and stop the object from being instantiated.
my logic is that if i can make sure the object is only instantiated if the arguments are valid then i can safely assume they will be throughout the object's life. this also makes it more efficient as I don't have to fully create the object if incorrect parameters are passed.
however, returning NULL (or false) from the __construct() function doesn't stop the object from being created, it merely skips the rest of the initialization and can still be used normally.
one way around this would be to validate the entries before attempting to create the object, but now i'm curious as to whether it's possible to tell a constructor to 'abort'
thanks!
one class' __construct() receives 2 arguments as parameters, validates them and if they are both valid stores them and initializes the rest of the class. if validation fails, i made it return NULL in order to try and stop the object from being instantiated.
my logic is that if i can make sure the object is only instantiated if the arguments are valid then i can safely assume they will be throughout the object's life. this also makes it more efficient as I don't have to fully create the object if incorrect parameters are passed.
however, returning NULL (or false) from the __construct() function doesn't stop the object from being created, it merely skips the rest of the initialization and can still be used normally.
one way around this would be to validate the entries before attempting to create the object, but now i'm curious as to whether it's possible to tell a constructor to 'abort'
thanks!
