hubzero / hubzero-cms

Platform for Scientific Collaboration
https://hubzero.org
GNU General Public License v2.0
46 stars 57 forks source link

[PURR-82] added __isset() to Relational class #1662

Closed JackS9 closed 11 months ago

JackS9 commented 1 year ago

This is an alternate solution to PR 1661

zooley commented 1 year ago

Just a note that this functionality already exists on the Relational class in the form of the hasAttribute() method. Adding an __isset magic method isn't a bad idea, though, but should probably just return the other method (or vice-versa).

    /**
     * Check if attributes (i.e. field) on the model is set
     *
     * @param  string  $name   The key to check if set
     * @return  boolean 
     */
    public function __isset($name)
    {
        return $this->hasAttribute($name);
    }
JackS9 commented 1 year ago

I changed to what Shawn suggested; however, I noticed that __get() could also use hasAttribute()

    // Next check for an attribute on the model
    if (isset($this->attributes[$name]))
    {
        return $this->attributes[$name];
    }