Skip to content

Instantly share code, notes, and snippets.

@o-shabashov
Created May 29, 2016 22:40
Show Gist options
  • Save o-shabashov/9befcc233f2a989a787f5b3b689750b9 to your computer and use it in GitHub Desktop.
Save o-shabashov/9befcc233f2a989a787f5b3b689750b9 to your computer and use it in GitHub Desktop.
Yii2 ActiveRecord->hasAttribute VS Model->hasProperty
<?php
// class ContactForm extends Model
$contact = new ContactForm();
// class User extends \yii\db\ActiveRecord
$user = new User();
isset($contact->email); // false
$contact->hasProperty('email'); // true
isset($user->email); // false
$user->hasProperty('email'); // false
$user->hasAttribute('email'); // true
$contact->email = 'test';
$user->email = 'test';
isset($contact->email); // true
$contact->hasProperty('email'); // true
isset($user->email); // true
$user->hasProperty('email'); // false
$user->hasAttribute('email'); // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment