Welcome Guest, Not a member yet? Register   Sign In
Model class- and member naming
#1

[eluser]mark17[/eluser]
L.S.

The following fatal error is what i get in at least CodeIgniter 1.6.1, perhaps it's present in older versions but haven't tried it.

Code:
Fatal error: Cannot access private property Test::$test in /home/markus/public_html/brochureselectie.nl/trunk/sys/libraries/Model.php on line 69

This is produced when some model attempts to set a classvariable with the same name, like the snippet below.

Code:
<?php

class Test extends Model {

    private $test = NULL;

    public function __construct() {
        parent::__construct();

        $this->test = 'TEST';
    }

    public function getTest() {
        return $this->test;
    }

}

?>

I'm unsure whether or not this is an existing and an already reported bug, although a search for model related issues did not result in any bug alike.

Any thoughts on this one? It should not be a problem to have ambiguous naming within some class. This could also cause dynamically generated errors when some code using __set() methods to dynamically assign new variables to the scope.

Code:
<?php

class Test extends MY_Model {

    //private $test = NULL;

    public function __construct() {
        parent::__construct();

        $this->test = 'TEST';
    }

    public function getTest() {
        return $this->test;
    }

    public function __set($b, $c) {
        var_dump($b);
        print '<p>';
        var_dump($c);
    }

}

?&gt;

The last snippet will generate the following output, possibly because __set will catch not only my assignment of $this->test but a lot more internal stuff. Please try...

Regards,
#2

[eluser]Dan Murfitt[/eluser]
I'm also getting this problem with a model I've created containing a private $email field. I've only noticed the problem once I've started to use the email library (which I guess has a private $email field too?). Here's the message I'm getting:

Code:
Fatal error: Cannot access private property Usermodel::$email in C:\xampp\htdocs\pm4\system\libraries\Model.php on line 69

Are there reserved field names which can't be used in custom libraries and models?

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB