Пример #1
0
 function __construct()
 {
     static $x = 0;
     if ($x) {
         print "Infinite loop...\n";
     } else {
         $x++;
         parent::__construct(1);
         testclass::__construct(2);
         call_user_func(array('parent', '__construct'), 3);
         call_user_func(array('testclass', '__construct'), 4);
         call_user_func(array('testclass', 'testclass'), 5);
     }
 }
Пример #2
0
	public function testFunc(){
		echo "\n".'I`m the up';
	}
}

class testClass extends parentClass{
	var $nick = '';

	public function __construct($nick){
		$this->nick = $nick;
	}

	public function Display(){
		echo $this->nick;  
		$this->testFunc();
	}
}


$otherClass1 = new testClass('frank');  //frank
$otherClass1->Display();   //I'm the up

/*
这样的代码最后的输出结果是什么呢?关键是看testFunc()方法。

    如果在类中用$this调用一个当前类中不存在的方法或变量,它会依次去父类寻找,直到找不到再报错
    基于第一条,如果找到了需要的方法或变量,就会停止寻找,如果其上级父类中还有同样的,则选择当前找到的

*/
?>
Пример #3
0
		$this->num++;
	}


	function display(){
		echo self::$count,'<br />';
		echo $this->num, '<br />';
	}
}


$oTest1 = new testClass();
$oTest1->display();  //输出1,1


$oTest2 = new testClass();
$oTest2->display(); //输出2,1


/*
上面例子中self::$cout始终指向该类本身,而$num是单独存在于各个具体实例中的。
总结:

  $this 指向当前的实例

  $parent 是父类的引用

  self 对当前类本身的一个引用
*/

Пример #4
0
<?php

ini_set('display_errors', 1);
error_reporting(E_ALL);
// include the autoloader
require 'vendor/autoload.php';
Illuminate\Support\ClassLoader::register();
// create test class
$n = new testClass();
$n->testme();
// the required libs
use Illuminate\View\FileViewFinder;
use Illuminate\Filesystem\Filesystem;
use Illuminate\View\Compilers\BladeCompiler;
use Illuminate\View\Engines\CompilerEngine;
use Illuminate\Events\Dispatcher;
use Illuminate\Container\Container;
use Illuminate\View\Factory;
use Illuminate\View\Engines\EngineResolver;
use Illuminate\View\View;
class testClass
{
    function testme()
    {
        // create a template
        $r = $this->loadBlade('not-sure-what-this-does', __DIR__ . '/app/views/test.blade.php', array('testvar' => ' timestamp: ' . time()));
        // render the template
        echo $r->render();
    }
    function loadBlade($view, $viewPath = false, $data = array())
    {
Пример #5
0
<?php
header('Content-Type:text/html; charset=utf-8');
/*
上面例子中,$this->display();   其实就是 $otestClass1->nick,因此$this究竟指向哪是由所实例化的对象决定的,指向当前对象实例的指针。包括变量、方法都是如此
*/

class testClass{
	var $nick = '';

	public function __construct($nick){
		$this->nick = $nick;
	}

	public function Display(){
		echo $this->nick;

	}
}

$otherClass1 = new testClass('frank');
$otherClass1->Display();   //显示frank
?>
Пример #6
0
<?php

class testClass
{
    protected $property = 'value';
    public function testInclude()
    {
        include __DIR__ . '/class_include_nested_1.inc';
    }
}
$test = new testClass();
$test->testInclude();