On Fri, 2003-04-04 at 10:45, Dan Rossi wrote: > what exactly do namespaces do , i can sorta see whats its doin > > and this is what i want !! > > <?php > define('NUM', 10); > try { > if (NUM < 20) { > throw new Exception( > NUM . " is too small!" > ); > } > } catch (Exception $e) { > echo $e->getMessage(); > echo "\n<br />\n"; > } > ?> > > > function __construct() { > echo "peel..peel.."; > echo "\n<br />\n"; > } > > cool > > when is this actually used ? > function __destruct() { > echo "slip... crack!"; > echo "\n<br />\n"; > } > > yep this is cool i've already tested it out and it works , but what is the > whole point of private and protected again ? i've been reading the java > intro on the sun site and it goes into detail about it > http://ny1.php.net/talks/show.php/php5intro/13 > > hmm i soughta found php4 cant do this > > function add_agent($name) { > array_push($this->agents, $name); > } > } > > class cia_administration extends cia { > function __construct() { > $this->add_agent('Sterling'); > $this->add_agent('Zeev'); > $this->add_agent('Andi'); > $this->add_agent('Rasmus'); > $this->add_agent('Thies'); > } > } > > i had to call the parent class constructor into the base constructor first > to use its functions ?>?
Constructors in PHP5 are unified. This means you don't have to be aware of your parent class name while coding (so, for example, if you change what class you inherit, you don't have to dig to find where the parent constructor was called. > > i dont get this http://ny1.php.net/talks/show.php/php5intro/25 > It misses something without my explanation. :) PHP5 has native support for overloading access to properties and methods. Take the following: <?php class foo { private $overloads; function __construct() { $this->overloads = array( "name" => "Sterling", "address" => "More Spam Mail", "email" => "Even More Spam Mail" ); } function __get($name) { return $this->overloads[$name]; } function __set($name, $value) { $this->overloads[$name] = $value; } } $f = new foo; // undefined, __get method will be called, and it will // return the appropriate entry from overloads var_dump($f->address); ?> > wots the point of this ? http://ny1.php.net/talks/show.php/php5intro/28 > Abstract allows you to define certain methods that *must* be implemented in child classes. It also makes sure you can't instantiate parent classes (as they are incomplete). Its really a good way of passing interface contracts onto child classes. Take the example in my presentation, and copy it into your editor. Then remove the paint() method, and the corresponding method call from the child class. Without abstract being specified, this would still work; with abstract, watch what happens. -sterling -- Good judgement comes from experience, and experience comes from bad judgement. - Fred Brooks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php