views:

44

answers:

2

hello

is it a good practice to use private properties in codeigniter controllers ?

for example

<?php

class X_controller extends Controller{

       private $data;

       function __construct(){
            parent::Controller();
            $this->data = "xx"
       }

       function index(){
           //use $this->data somewhere here ?
       }
}
A: 

It's not a good practice with CodeIgniter, it's a good practice for oriented-object programing. You will access to this data somewhere else? If not, keep it privately.

Isern Palaus
+1  A: 

Nothing can directly access Controllers by default, but if in the future decide to use HMVC or extend other controllers (DO NOT TRY THIS UNTIL YOU KNOW WHY, WHEN AND HOW) then using private could give you some difficulties.

I use protected for mine, but it really doesn't make much difference for general CodeIgniter use.

Phil Sturgeon