{
        $this->adultClassVar = 123;
        return $this->adultClassVar;
    }
}
class Child extends Adult
{
    static $childStaticVar;
    public $childInstanceVar;
    function __construct()
    {
        $this->isExtended = true;
    }
    function childValue()
    {
        //	self::$childStaticVar = 123;
        $this->childInstanceVar = 123;
        // TODO - Adult static variable needs to be accessed via Adult.adultStaticVar not
        // Child.adultStaticVar in the generated javascript. Which may be tricky.
        //	echo "This is a child method. \n" + $this->childInstanceVar + " " + self::$childStaticVar + " " +  + $this->adultClassVar + " " + self::$adultStaticVar;
        return 12345;
    }
}
$adultOnly = new Adult();
assert($adultOnly->adultValue(), 123);
assert($adultOnly->isExtended, false);
$child = new Child();
assert($child->childValue(), 12345);
assert($child->adultValue(), 123);
assert($child->isExtended, true);
testEnd();
Exemple #2
0
 public function crossing()
 {
     River::LogHeader();
     // by inserting header delete all previous info in log file
     if (Config::getChildren() == 1) {
         echo "Not enough children to cross the river. Are you sure you took all your kids from home?";
     } else {
         if (Config::getChildren() == 0) {
             if (Config::getAdults() == 0) {
                 echo "I guess all are staying at home, nobody wanted to move to the other bank, yep?";
             } else {
                 echo "Not enough children to cross the river. Are you sure you took all your kids from home?";
             }
         } else {
             if (Config::getAdults() > 0) {
                 for ($i = 0; $i < Config::getAdults(); $i++) {
                     $this->move++;
                     $this->transfer($this->move);
                     Child::twoChildrenMove();
                     $this->move++;
                     $this->transfer($this->move);
                     Child::childBack();
                     $this->move++;
                     $this->transfer($this->move);
                     Adult::move();
                     $this->move++;
                     $this->transfer($this->move);
                     Child::childBack();
                 }
             }
             if (Config::getChildren() > 2) {
                 for ($i = 0; $i < Config::getChildren() - 2; $i++) {
                     $this->move++;
                     $this->transfer($this->move);
                     Child::childMove();
                     $this->move++;
                     $this->transfer($this->move);
                     Child::childBack();
                 }
             }
             // move boatOwner - goes in any case
             $this->move++;
             $this->transfer($this->move);
             Child::twoChildrenMove();
             $this->move++;
             $this->transfer($this->move);
             Child::ChildBack();
             $this->move++;
             $this->transfer($this->move);
             Fisherman::move();
             $this->move++;
             $this->transfer($this->move);
             Child::childBack();
             //finally move 2 last children to right bank - goes in any case
             $this->move++;
             $this->transfer($this->move);
             Child::twoChildrenMove();
             echo "they will have to cross the river " . $this->move . " times.";
         }
     }
 }