Welcome Guest, Not a member yet? Register   Sign In
__get() and __set() with 1.5.4
#5

[eluser]Unknown[/eluser]
Thanks to everyone who replied; I understand the problem now (my description above is incorrect). Jim's answer works if you're dealing with a fixed set of class variables, and psycow's correct about the underscore (but there are a bunch more assignments to be accounted for).

Sophistry, I'm staring at the code and I don't see how to apply get_class() to this situation; I'd be grateful if you could spell it our for me?

As a synthesis of everyone's suggestions I came up with this (dropping the valid{$name}() call as it was confusing the issue):

Code:
public function __set( $name, $value )
    {
        if ( $name[0] == '_' || $name == 'config' || $name == 'input' || $name == 'benchmark' || $name == 'uri' || $name == 'output' || $name == 'lang' || $name == 'load' )
        {
            $this->$name = $value;
        }
        else
        {
            $this->data[$name] = $value;
        }
        return true;
    }

But of course that's too brittle to be used in anger.

I think that dynamically creating class "variables" at runtime using __set() and a private array just won't work reliably when you're extending a base class. A PHP problem, not a CI problem.


Messages In This Thread
__get() and __set() with 1.5.4 - by El Forum - 09-27-2007, 06:47 PM
__get() and __set() with 1.5.4 - by El Forum - 09-28-2007, 08:59 PM
__get() and __set() with 1.5.4 - by El Forum - 09-30-2007, 07:15 AM
__get() and __set() with 1.5.4 - by El Forum - 09-30-2007, 08:11 AM
__get() and __set() with 1.5.4 - by El Forum - 09-30-2007, 06:22 PM
__get() and __set() with 1.5.4 - by El Forum - 09-30-2007, 06:48 PM
__get() and __set() with 1.5.4 - by El Forum - 08-02-2008, 08:38 AM
__get() and __set() with 1.5.4 - by El Forum - 04-01-2009, 10:31 AM
__get() and __set() with 1.5.4 - by El Forum - 12-02-2010, 03:38 AM



Theme © iAndrew 2016 - Forum software by © MyBB