CakePHP-2.0: difference between using public and var

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 is the difference between using public and using var?

+4
source share
2 answers

var is an obsolete visibility keyword, 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 to 5.1.3, using it generates an E_STRICT warning.

Since it has been replaced with the public keyword, the new cake follows the new standard. See a working example here .

+7
source

"var" existed before PHP5, which introduced visibility into objects. Although it is still technically sound, you should avoid using it and use the right visibility keywords.

To answer your question, they are identical in functionality. However, "var" is deprecated and will soon disappear.

+3
source

All Articles