Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 431
shibly Avatar asked Dec 28 '22 12:12

shibly


2 Answers

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.

like image 93
Stop Slandering Monica Cellio Avatar answered Jan 07 '23 04:01

Stop Slandering Monica Cellio


"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.

like image 43
John Cartwright Avatar answered Jan 07 '23 05:01

John Cartwright