Welcome Guest, Not a member yet? Register   Sign In
Entity magic get by reference
#1

(This post was last modified: 06-02-2020, 08:29 AM by beng.)

Hi there,

I am trying to build a very loose lazy lead within my entities for pivots.

for e.g (not a working example, just so you can get the logic):

PHP Code:
class Car extends Entity
{
    protected 
$drivers 'load';

    public function 
setDrivers()
    {
        
$this->drivers = (Model())->findAll();
    }
    
    public function 
getDrivers()
    {
        if (
$this->drivers === 'load')
        { 
            
$this->setDrivers();
        }
        return 
$this->drivers
    }


As the getXxxx method call the entity magic __get method I am getting the
Code:
ErrorException Indirect modification of overloaded property
error when calling Car->drivers.

This can be solved very easily by me modifying the core Entity class to make the magic get "by reference" e.g

PHP Code:
&__get(string $key

My question is is CI4 purposely built to not pass by reference and will this break anything / cause a problem with CI in any way?

Any info would be much appreciated as I dont want to break something deep in the workings of CI.

Thanks in advance,
Ben
Reply




Theme © iAndrew 2016 - Forum software by © MyBB