Exemplo n.º 1
0
 public function testPyramid()
 {
     $test = new test1();
     $result = $test->fortest();
     // echo $result;  die;
     $output = '';
     $this->assertTrue($result);
     $this->assertEquals($output, $result);
 }
Exemplo n.º 2
0
    public static function __callStatic($name, $args)
    {
        echo 'Hello from ' . __CLASS__ . '::' . __FUNCTION__ . PHP_EOL;
    }
    public function __call($name, $args)
    {
        echo 'Hello from ' . __CLASS__ . '->' . __FUNCTION__ . PHP_EOL;
    }
}
spl_autoload_register(function ($class) {
    if (class_exists($class)) {
        return true;
    }
    $try_model = 'model_' . $class;
    if (class_exists($try_model)) {
        eval('class ' . $class . ' extends ' . $try_model . '{};');
        return true;
    }
});
// Existing class call
$ts = microtime();
model_test1::hello();
$model_test1 = new model_test1();
$model_test1->hello();
echo round(microtime() - $ts, 5) . PHP_EOL;
// Virtual class call
$ts = microtime();
test1::hello();
$test1 = new test1();
$test1->hello();
echo round(microtime() - $ts, 5) . PHP_EOL;
Exemplo n.º 3
0
 function test()
 {
     $test1 = new test1();
     $test1->test();
 }
Exemplo n.º 4
0
 public function func2()
 {
     //return "word";
     self::$aa = self::$aa . "bbb";
     return self::$aa;
 }
Exemplo n.º 5
0
{
    function go()
    {
        include_once "myinclude.php";
    }
}
class test2
{
    function go()
    {
        echo 'k';
    }
}
$time_start = getmicrotime();
for ($i = 0; $i < 10000; $i++) {
    $bla = new test1();
    $bla->go();
}
echo '<br><br>';
$time_end = getmicrotime();
$time = $time_end - $time_start;
echo 'Page generated in ', number_format($time, 3), ' seconds<br><br><br><br>';
$time_start = getmicrotime();
for ($i = 0; $i < 10000; $i++) {
    $bla = new test2();
    $bla->go();
}
echo '<br><br>';
$time_end = getmicrotime();
$time = $time_end - $time_start;
echo 'Page generated in ', number_format($time, 3), ' seconds<br>';
Exemplo n.º 6
0
$std4->userId = 7;
$std4->username = '******';
$array = array($std1, $std2, $std3, $std4);
foreach ($array as $obj) {
    echo $obj->userId, '--', $obj->username, '<br/><br/>';
}
//print_r($array);
//对象的属性可以是数组
class test1
{
    public $users = array('Tom', 'John', 'Rose');
    function fun1()
    {
        $std1 = new stdClass();
        $std1->userId = 5;
        $std1->username = '******';
        $std2 = new stdClass();
        $std2->userId = 9;
        $std2->username = '******';
        $std3 = new stdClass();
        $std3->userId = 22;
        $std3->username = '******';
        $std4 = new stdClass();
        $std4->userId = 36;
        $std4->username = '******';
        return array($std1, $std2, $std3, $std4);
    }
}
$t = new test1();
echo $t->users[1], '<br/><br/>';
echo $t->fun1()[2]->username, '<br/><br/>';
Exemplo n.º 7
0
        return $obj;
    }
    function fun2()
    {
        echo 'BBB';
    }
}
class test2
{
    function fun3()
    {
        echo 'AAAA';
    }
    function fun4()
    {
        echo '123';
    }
}
class test3
{
    function fun5()
    {
        echo '我是test3里fun5()';
    }
}
$t = new test1();
//链式写法
$t->obj->fun5();
//$t的的属性返回值为对象,即可以继续访问属性
$t->fun1()->fun3();
//$t的方法的返回值也是对象,即也可以再次调用方法
Exemplo n.º 8
0
        for ($i = 1; $i <= $line; ++$i) {
            //run the loop upto number of lines
            for ($s = 1; $s <= $line - $i; ++$s) {
                // run the loop to set the space for pyramid
                echo " ";
            }
            if ($i == $line) {
                // run at the end of the line
                for ($s = 1; $s <= 2 * $line - 1; ++$s) {
                    echo "1";
                }
            } else {
                // run the loop based on the line number
                while ($a != 2 * $i - 1) {
                    echo ++$count;
                    ++$a;
                }
            }
            $a = 0;
            echo "\n";
            //for line break at the end of every main loop
        }
    }
    public function fortest()
    {
        $test = $this->pyramid();
        return true;
    }
}
$test = new test1();
echo $test->pyramid();
Exemplo n.º 9
0
function __autoload($class)
{
    eval('class test1 extends test2 {}');
    test1::use_stack(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30);
}