I have few questions regarding the Class object in PHP :
1. is there a way to restrict the creation of class object only from particular other class object ? so, the user won't be permitted to explicitly create object by issuing NEW object() from main script.
User can only get the object by this way :
$myobj=$parobj->create_obj();
2. I made some object initialization via constructor function, whereby the constructor will possibly return TRUE or FALSE condition. I wonder how to check the result value returned by constructor function ?(without calling this constructor manually).
thanks.
Class Object
Moderator: General Moderators
I think what you are looking for is abstract class.
This should be a good start->http://www.devshed.com/c/a/PHP/Abstract ... ith-PHP-5/
This should be a good start->http://www.devshed.com/c/a/PHP/Abstract ... ith-PHP-5/
Last edited by wtf on Mon Jul 24, 2006 11:49 pm, edited 1 time in total.
If using PHP5 you can use an exception as a pseudo-boolean..
Code: Select all
class MyClass
{
public function __construct ($sky, $colour = 'blue')
{
if ($sky != $colour) {
throw new Exception ('blah');
}
}
}
try {
$foo = new MyClass('grey');
} catch (Exception $e) {
//do something here
}
?>