self in inherited methods

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Is it right that 'self' in inherited method still points to the parent?
If it is, can you explain it? It makes me worry :)

A piece of code below for example

<?php
class MyParent {
       const NAME = 'MyParent';
       public function get_instance() {
               return new self;
       }
       public function get_another_instance() {
               $class_name = get_class($this);
               return new $class_name;
       }
       public function get_name() {
               return self::NAME;
       }
}

class MyClass extends MyParent {
       const NAME = 'MyClass';
}

$a = new MyClass;
$b = $a->get_instance();
$c = $a->get_another_instance();

echo $a->get_name(),"\n";
echo get_class($b),"\n";
echo get_class($c),"\n";
?>



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux