在PHP中:(雙冒號)和->(箭頭)有什么區別?在PHP中訪問方法有兩種不同的方法,但是有什么不同呢?$response->setParameter('foo', 'bar');和sfConfig::set('foo', 'bar');我假設->(大于符號或雪佛龍的破折號)用于變量的函數,以及::(雙冒號)用于類的函數。對,是這樣?是=>賦值運算符只用于分配數組中的數據?這與=賦值操作符用于實例化或修改變量?
3 回答
HUX布斯
TA貢獻1876條經驗 獲得超6個贊
::
class Math {
public static function sin($angle) {
return ...;
}}$result = Math::sin(123);::
class Rectangle {
protected $x, $y;
public function __construct($x, $y) {
$this->x = $x;
$this->y = $y;
}}class Square extends Rectangle {
public function __construct($x) {
parent::__construct($x, $x);
}}->
class Hello {
public function say() {
echo 'hello!';
}}$h = new Hello();$h->say();
慕哥9229398
TA貢獻1877條經驗 獲得超6個贊
class Test {
public $name;
public function __construct() {
$this->name = 'Mrinmoy Ghoshal';
}
public static function doWrite($name) {
print 'Hello '.$name;
}
public function write() {
print $this->name;
}}Test::doWrite('Mrinmoy');
// Output: Hello Mrinmoy.
write
- 3 回答
- 0 關注
- 383 瀏覽
添加回答
舉報
0/150
提交
取消
