Skip to content

Commit edf1d83

Browse files
committed
Check for null attribute or null cast in getAttribute method
1 parent 213d254 commit edf1d83

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/Kodeine/Metable/Metable.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -437,16 +437,20 @@ public function getAttribute($key) {
437437
return $attr;
438438
}
439439

440-
// Check if the key is a casted attribute.
441-
if ( $this->hasCast( $key ) ) {
442-
return $this->castAttribute( $key, $attr );
443-
}
444-
445440
// Don't get meta data if fluent access is disabled.
446441
if ( property_exists( $this, 'disableFluentMeta' ) && $this->disableFluentMeta ) {
447442
return $attr;
448443
}
449444

445+
// It is possible that attribute exists, or it has a cast, but it's null, so we check for that
446+
if ( array_key_exists( $key, $this->attributes ) ||
447+
array_key_exists( $key, $this->casts ) ||
448+
$this->hasGetMutator( $key ) ||
449+
$this->hasAttributeMutator( $key ) ||
450+
$this->isClassCastable( $key ) ) {
451+
return $attr;
452+
}
453+
450454
// If key is a relation name, then return parent value.
451455
// The reason for this is that it's possible that the relation does not exist and parent call returns null for that.
452456
if ( $this->isRelation( $key ) && $this->relationLoaded( $key ) ) {

0 commit comments

Comments
 (0)