Ejemplo n.º 1
0
 public function testMultipleSingletons()
 {
     $instance_one = One::getInstance();
     $instance_two = Two::getInstance();
     $this->assertInstanceOf("oscarpalmer\\Mordin\\Singleton", $instance_one);
     $this->assertInstanceOf("oscarpalmer\\Mordin\\Singleton", $instance_two);
     $this->assertNotSame($instance_one, $instance_two);
 }
    {
        echo "{$var} Students";
    }
}
// Student = new Student();
// echo $student->total_students;
echo Student::$total_students . "<br/>";
echo Student::welcome_students() . "<br/>";
echo Student::welcome_students("Greetings") . "<br/>";
Student::$total_students = 1;
echo Student::$total_students . "<br/>";
// static variables are shared throughout the inheritance tree
class One
{
    static $foo;
}
class Two extends One
{
}
class Three extends Two
{
}
One::$foo = 1;
Two::$foo = 2;
Three::$foo = 3;
echo One::$foo;
// 3
echo Two::$foo;
//3
echo Three::$foo;
//3
Ejemplo n.º 3
0
        $this->d = $letters_4;
    }
    public function printEverthing()
    {
        echo $this->a . "," . $this->b . "," . $this->c . "," . $this->d;
    }
}
class Three extends Two
{
    public $e;
    public $f;
    function __construct($letters_1, $letters_2, $letters_3, $letters_4, $letters_5, $letters_6)
    {
        $this->a = $letters_1;
        $this->b = $letters_2;
        $this->c = $letters_3;
        $this->d = $letters_4;
        $this->e = $letters_5;
        $this->f = $letters_6;
    }
    public function printEverthing()
    {
        echo $this->a . "," . $this->b . "," . $this->c . "," . $this->d . "," . $this->e . "," . $this->f;
    }
}
$object1 = new One("dog", "cat" . PHP_EOL);
$object2 = new Two("horse", "pig", "squirrel", "monkey" . PHP_EOL);
$object3 = new Three("woodchuck", "mole", "giraffe", "shark", "deer", "robin");
$object1->printEverthing();
$object2->printEverthing();
$object3->printEverthing();
Ejemplo n.º 4
0
Archivo: Simple.php Proyecto: ezrra/PHP
<?php

trait Simple
{
    public function className()
    {
        return __CLASS__ . "<br>";
    }
}
class One
{
    use Simple;
}
class Two
{
    use Simple;
}
$one = new One();
echo $one->className();
$two = new Two();
echo $two->className();