gpt4 book ai didi

php - CakePHP-2.0:使用 public 和 var 的区别

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:03:46 27 4
gpt4 key购买 nike

CakePHP-2.0 有这个=>

// Even in your cakephp 2.1.x we have this format
<?php
class PostsController extends AppController {
public $helpers = array ('Html','Form');
public $name = 'Posts';

public function index() {
$this->set('posts', $this->Post->find('all'));
}
}
?>

CakePHP-1.3.10 有这个=>

<?php
class PostsController extends AppController {
var $helpers = array ('Html','Form');
var $name = 'Posts';

function index() {
$this->set('posts', $this->Post->find('all'));
}
}
?>

使用 public 和使用 var 有什么区别?

最佳答案

var 已弃用 visibility在功能上等同于 public 的关键字。

来自文档:

Note: The PHP 4 method of declaring a variable with the var keyword is still supported for compatibility reasons (as a synonym for the public keyword). In PHP 5 before 5.1.3, its usage would generate an E_STRICT warning.

由于它已被关键字 public 取代,新蛋糕遵循新标准。查看工作示例 here .

关于php - CakePHP-2.0:使用 public 和 var 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7852268/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com