2010-12-15 60 views

回答

2

这是一个简单的例子。

<?php 
class HelloWorld { 
var $message = ''; 

function __construct() { 
    $this->message = 'Hello World'; 
} 

function say_hi() { 
    echo $this->message; 
} 
} 
?> 
2

你可以从你的类访问的每个变量在所有的方法与此:

$this->myVar; 
0

一个变量可以在类中声明。

<?php 
class ExampleClass { 
public $pub; // accessable anywhere 
protected $pro; // can only be called by this class and classes that extend this class (inherit) 
private $pri; // only accessed by this class 

}?> 

变量范围进行说明here

相关问题