Welcome Guest, Not a member yet? Register   Sign In
use of $this
#4

(12-03-2016, 03:23 AM)040mag Wrote: 1. Is it better to access "$data" the OOP way ("$this->data") as in muuuchos example or should I access it  by "$data" as the CI documentation does, and are the two ways technically equivalent?

These are not different ways of accessing the same thing. It's 2 different things, neither is better.

(12-03-2016, 03:23 AM)040mag Wrote: 2. Then a basic question about inheritance. Lets say I have a class "Car" that inherits "MY_Controller".  Should I access "$data" (or "$this-data") direct or is it better to declare it "private" in "MY_Controller" and then use getter and setter functions? In other words: is it good practice to use data encapsulation when you want to access data from a class that you inherit from?

The latter is not possible - private symbols are only accessible from inside the class that declares them.
Even if you call a getter declared in MY_Controller, it will still be executed inside the context of Car, and the property will be inaccessible.
Reply


Messages In This Thread
use of $this - by muuucho - 12-02-2016, 05:16 AM
RE: use of $this - by Narf - 12-02-2016, 08:40 AM
RE: use of $this - by 040mag - 12-03-2016, 03:23 AM
RE: use of $this - by Narf - 12-03-2016, 08:10 AM



Theme © iAndrew 2016 - Forum software by © MyBB