2010-12-15 91 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

相關問題