CakePHP-2.0 has this=>
// 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 had this=>
<?php
class PostsController extends AppController {
var $helpers = array ('Html','Form');
var $name = 'Posts';
function index() {
$this->set('posts', $this->Post->find('all'));
}
}
?>
What's the difference between using public and using var ?
var
is a deprecated visibility keyword that is functionally equal to public
.
From the docs:
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.
As it's been replaced by the keyword public
, the new cake is following the new standard. See working example here.
"var" existed prior to PHP5 which introduced visibility to objects. Although it still is technically valid, you should avoid it's use and use proper visibility keywords.
To answer your question, they are identical in functionality. However, "var" is deprecated and will go away soon.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With