Inheritance | yii\base\BaseObject |
Implements | yii\base\Configurable |
Subclasses | yii\apidoc\commands\ApiController, yii\apidoc\commands\GuideController, yii\apidoc\components\BaseController, yii\apidoc\models\BaseDoc, yii\apidoc\models\ClassDoc, yii\apidoc\models\ConstDoc, yii\apidoc\models\Context, yii\apidoc\models\EventDoc, yii\apidoc\models\FunctionDoc, yii\apidoc\models\InterfaceDoc, yii\apidoc\models\MethodDoc, yii\apidoc\models\ParamDoc, yii\apidoc\models\PropertyDoc, yii\apidoc\models\TraitDoc, yii\apidoc\models\TypeDoc, yii\apidoc\renderers\ApiRenderer, yii\apidoc\renderers\BaseRenderer, yii\apidoc\renderers\GuideRenderer, yii\apidoc\templates\bootstrap\ApiRenderer, yii\apidoc\templates\bootstrap\GuideRenderer, yii\apidoc\templates\bootstrap\SideNavWidget, yii\apidoc\templates\bootstrap\assets\AssetBundle, yii\apidoc\templates\bootstrap\assets\HighlightBundle, yii\apidoc\templates\bootstrap\assets\JsSearchAsset, yii\apidoc\templates\html\ApiRenderer, yii\apidoc\templates\html\GuideRenderer, yii\apidoc\templates\json\ApiRenderer, yii\apidoc\templates\online\ApiRenderer, yii\apidoc\templates\pdf\GuideRenderer, yii\authclient\AuthAction, yii\authclient\BaseClient, yii\authclient\BaseOAuth, yii\authclient\CacheStateStorage, yii\authclient\Collection, yii\authclient\OAuth1, yii\authclient\OAuth2, yii\authclient\OAuthToken, yii\authclient\OpenId, yii\authclient\OpenIdConnect, yii\authclient\SessionStateStorage, yii\authclient\clients\Facebook, yii\authclient\clients\GitHub, yii\authclient\clients\Google, yii\authclient\clients\GoogleHybrid, yii\authclient\clients\LinkedIn, yii\authclient\clients\Live, yii\authclient\clients\Twitter, yii\authclient\clients\TwitterOAuth2, yii\authclient\clients\VKontakte, yii\authclient\clients\Yandex, yii\authclient\signature\BaseMethod, yii\authclient\signature\HmacSha, yii\authclient\signature\HmacSha1, yii\authclient\signature\PlainText, yii\authclient\signature\RsaSha, yii\authclient\signature\RsaSha1, yii\authclient\widgets\AuthChoice, yii\authclient\widgets\AuthChoiceAsset, yii\authclient\widgets\AuthChoiceItem, yii\authclient\widgets\AuthChoiceStyleAsset, yii\authclient\widgets\GooglePlusButton, yii\base\Action, yii\base\ActionEvent, yii\base\ActionFilter, yii\base\Application, yii\base\Behavior, yii\base\Component, yii\base\Controller, yii\base\DynamicModel, yii\base\ErrorHandler, yii\base\Event, yii\base\InlineAction, yii\base\Model, yii\base\ModelEvent, yii\base\Module, yii\base\Object, yii\base\Request, yii\base\Response, yii\base\Security, yii\base\Theme, yii\base\View, yii\base\ViewEvent, yii\base\ViewRenderer, yii\base\Widget, yii\base\WidgetEvent, yii\behaviors\AttributeBehavior, yii\behaviors\AttributeTypecastBehavior, yii\behaviors\AttributesBehavior, yii\behaviors\BlameableBehavior, yii\behaviors\CacheableWidgetBehavior, yii\behaviors\OptimisticLockBehavior, yii\behaviors\SluggableBehavior, yii\behaviors\TimestampBehavior, yii\bootstrap\ActiveField, yii\bootstrap\ActiveForm, yii\bootstrap\Alert, yii\bootstrap\BootstrapAsset, yii\bootstrap\BootstrapPluginAsset, yii\bootstrap\BootstrapThemeAsset, yii\bootstrap\Button, yii\bootstrap\ButtonDropdown, yii\bootstrap\ButtonGroup, yii\bootstrap\Carousel, yii\bootstrap\Collapse, yii\bootstrap\Dropdown, yii\bootstrap\InputWidget, yii\bootstrap\Modal, yii\bootstrap\Nav, yii\bootstrap\NavBar, yii\bootstrap\Progress, yii\bootstrap\Tabs, yii\bootstrap\ToggleButtonGroup, yii\bootstrap\Widget, yii\caching\ApcCache, yii\caching\ArrayCache, yii\caching\Cache, yii\caching\ChainedDependency, yii\caching\DbCache, yii\caching\DbDependency, yii\caching\DbQueryDependency, yii\caching\Dependency, yii\caching\DummyCache, yii\caching\ExpressionDependency, yii\caching\FileCache, yii\caching\FileDependency, yii\caching\MemCache, yii\caching\MemCacheServer, yii\caching\TagDependency, yii\caching\WinCache, yii\caching\XCache, yii\caching\ZendDataCache, yii\captcha\Captcha, yii\captcha\CaptchaAction, yii\captcha\CaptchaAsset, yii\captcha\CaptchaValidator, yii\codeception\BasePage, yii\console\Application, yii\console\Controller, yii\console\ErrorHandler, yii\console\Request, yii\console\Response, yii\console\controllers\AssetController, yii\console\controllers\BaseMigrateController, yii\console\controllers\CacheController, yii\console\controllers\FixtureController, yii\console\controllers\HelpController, yii\console\controllers\MessageController, yii\console\controllers\MigrateController, yii\console\controllers\ServeController, yii\console\widgets\Table, yii\data\ActiveDataFilter, yii\data\ActiveDataProvider, yii\data\ArrayDataProvider, yii\data\BaseDataProvider, yii\data\DataFilter, yii\data\Pagination, yii\data\Sort, yii\data\SqlDataProvider, yii\db\ActiveQuery, yii\db\ActiveRecord, yii\db\AfterSaveEvent, yii\db\BaseActiveRecord, yii\db\BatchQueryResult, yii\db\CheckConstraint, yii\db\ColumnSchema, yii\db\ColumnSchemaBuilder, yii\db\Command, yii\db\Connection, yii\db\Constraint, yii\db\DataReader, yii\db\DefaultValueConstraint, yii\db\Expression, yii\db\ForeignKeyConstraint, yii\db\IndexConstraint, yii\db\Migration, yii\db\Query, yii\db\QueryBuilder, yii\db\Schema, yii\db\SqlToken, yii\db\SqlTokenizer, yii\db\TableSchema, yii\db\Transaction, yii\db\cubrid\ColumnSchemaBuilder, yii\db\cubrid\QueryBuilder, yii\db\cubrid\Schema, yii\db\mssql\ColumnSchema, yii\db\mssql\QueryBuilder, yii\db\mssql\Schema, yii\db\mssql\TableSchema, yii\db\mysql\ColumnSchema, yii\db\mysql\ColumnSchemaBuilder, yii\db\mysql\QueryBuilder, yii\db\mysql\Schema, yii\db\oci\ColumnSchemaBuilder, yii\db\oci\Command, yii\db\oci\QueryBuilder, yii\db\oci\Schema, yii\db\pgsql\ColumnSchema, yii\db\pgsql\QueryBuilder, yii\db\pgsql\Schema, yii\db\sqlite\ColumnSchemaBuilder, yii\db\sqlite\Command, yii\db\sqlite\QueryBuilder, yii\db\sqlite\Schema, yii\db\sqlite\SqlTokenizer, yii\debug\DbAsset, yii\debug\DebugAsset, yii\debug\LogTarget, yii\debug\Module, yii\debug\Panel, yii\debug\TimelineAsset, yii\debug\UserswitchAsset, yii\debug\actions\db\ExplainAction, yii\debug\components\search\Filter, yii\debug\components\search\matchers\Base, yii\debug\components\search\matchers\GreaterThan, yii\debug\components\search\matchers\GreaterThanOrEqual, yii\debug\components\search\matchers\LowerThan, yii\debug\components\search\matchers\SameAs, yii\debug\controllers\DefaultController, yii\debug\controllers\UserController, yii\debug\models\Router, yii\debug\models\UserSwitch, yii\debug\models\router\ActionRoutes, yii\debug\models\router\CurrentRoute, yii\debug\models\router\RouterRules, yii\debug\models\search\Base, yii\debug\models\search\Db, yii\debug\models\search\Debug, yii\debug\models\search\Event, yii\debug\models\search\Log, yii\debug\models\search\Mail, yii\debug\models\search\Profile, yii\debug\models\search\User, yii\debug\models\timeline\DataProvider, yii\debug\models\timeline\Search, yii\debug\models\timeline\Svg, yii\debug\panels\AssetPanel, yii\debug\panels\ConfigPanel, yii\debug\panels\DbPanel, yii\debug\panels\DumpPanel, yii\debug\panels\EventPanel, yii\debug\panels\LogPanel, yii\debug\panels\MailPanel, yii\debug\panels\ProfilingPanel, yii\debug\panels\RequestPanel, yii\debug\panels\RouterPanel, yii\debug\panels\TimelinePanel, yii\debug\panels\UserPanel, yii\debug\widgets\NavigationButton, yii\di\Container, yii\di\ServiceLocator, yii\elasticsearch\ActiveDataProvider, yii\elasticsearch\ActiveFixture, yii\elasticsearch\ActiveQuery, yii\elasticsearch\ActiveRecord, yii\elasticsearch\BatchQueryResult, yii\elasticsearch\BulkCommand, yii\elasticsearch\Command, yii\elasticsearch\Connection, yii\elasticsearch\DebugAction, yii\elasticsearch\DebugPanel, yii\elasticsearch\ElasticsearchTarget, yii\elasticsearch\Query, yii\elasticsearch\QueryBuilder, yii\faker\FixtureController, yii\filters\AccessControl, yii\filters\AccessRule, yii\filters\AjaxFilter, yii\filters\ContentNegotiator, yii\filters\Cors, yii\filters\HostControl, yii\filters\HttpCache, yii\filters\PageCache, yii\filters\RateLimiter, yii\filters\VerbFilter, yii\filters\auth\AuthMethod, yii\filters\auth\CompositeAuth, yii\filters\auth\HttpBasicAuth, yii\filters\auth\HttpBearerAuth, yii\filters\auth\HttpHeaderAuth, yii\filters\auth\QueryParamAuth, yii\gii\CodeFile, yii\gii\Generator, yii\gii\GiiAsset, yii\gii\Module, yii\gii\components\ActiveField, yii\gii\console\GenerateAction, yii\gii\console\GenerateController, yii\gii\controllers\DefaultController, yii\gii\generators\controller\Generator, yii\gii\generators\crud\Generator, yii\gii\generators\extension\Generator, yii\gii\generators\form\Generator, yii\gii\generators\model\Generator, yii\gii\generators\module\Generator, yii\grid\ActionColumn, yii\grid\CheckboxColumn, yii\grid\Column, yii\grid\DataColumn, yii\grid\GridView, yii\grid\GridViewAsset, yii\grid\RadioButtonColumn, yii\grid\SerialColumn, yii\i18n\DbMessageSource, yii\i18n\Formatter, yii\i18n\GettextFile, yii\i18n\GettextMessageSource, yii\i18n\GettextMoFile, yii\i18n\GettextPoFile, yii\i18n\I18N, yii\i18n\Locale, yii\i18n\MessageFormatter, yii\i18n\MessageSource, yii\i18n\MissingTranslationEvent, yii\i18n\PhpMessageSource, yii\jui\Accordion, yii\jui\AutoComplete, yii\jui\DatePicker, yii\jui\DatePickerLanguageAsset, yii\jui\Dialog, yii\jui\Draggable, yii\jui\Droppable, yii\jui\InputWidget, yii\jui\JuiAsset, yii\jui\Menu, yii\jui\ProgressBar, yii\jui\Resizable, yii\jui\Selectable, yii\jui\Slider, yii\jui\SliderInput, yii\jui\Sortable, yii\jui\Spinner, yii\jui\Tabs, yii\jui\Widget, yii\log\DbTarget, yii\log\Dispatcher, yii\log\EmailTarget, yii\log\FileTarget, yii\log\Logger, yii\log\SyslogTarget, yii\log\Target, yii\mail\BaseMailer, yii\mail\BaseMessage, yii\mail\MailEvent, yii\mongodb\ActiveFixture, yii\mongodb\ActiveQuery, yii\mongodb\ActiveRecord, yii\mongodb\BatchQueryResult, yii\mongodb\Cache, yii\mongodb\Collection, yii\mongodb\Command, yii\mongodb\Connection, yii\mongodb\Database, yii\mongodb\LogBuilder, yii\mongodb\Migration, yii\mongodb\Query, yii\mongodb\QueryBuilder, yii\mongodb\Session, yii\mongodb\console\controllers\MigrateController, yii\mongodb\debug\ExplainAction, yii\mongodb\debug\MongoDbPanel, yii\mongodb\file\ActiveQuery, yii\mongodb\file\ActiveRecord, yii\mongodb\file\Collection, yii\mongodb\file\Download, yii\mongodb\file\Query, yii\mongodb\file\StreamWrapper, yii\mongodb\file\Upload, yii\mongodb\gii\model\Generator, yii\mongodb\i18n\MongoDbMessageSource, yii\mongodb\log\MongoDbTarget, yii\mongodb\rbac\MongoDbManager, yii\mongodb\rbac\Permission, yii\mongodb\rbac\Role, yii\mongodb\validators\MongoDateValidator, yii\mongodb\validators\MongoIdValidator, yii\mutex\DbMutex, yii\mutex\FileMutex, yii\mutex\Mutex, yii\mutex\MysqlMutex, yii\mutex\OracleMutex, yii\mutex\PgsqlMutex, yii\rbac\Assignment, yii\rbac\BaseManager, yii\rbac\DbManager, yii\rbac\Item, yii\rbac\Permission, yii\rbac\PhpManager, yii\rbac\Role, yii\rbac\Rule, yii\redis\ActiveQuery, yii\redis\ActiveRecord, yii\redis\Cache, yii\redis\Connection, yii\redis\LuaScriptBuilder, yii\redis\Mutex, yii\redis\Session, yii\rest\Action, yii\rest\ActiveController, yii\rest\Controller, yii\rest\CreateAction, yii\rest\DeleteAction, yii\rest\IndexAction, yii\rest\OptionsAction, yii\rest\Serializer, yii\rest\UpdateAction, yii\rest\UrlRule, yii\rest\ViewAction, yii\smarty\ViewRenderer, yii\sphinx\ActiveDataProvider, yii\sphinx\ActiveFixture, yii\sphinx\ActiveQuery, yii\sphinx\ActiveRecord, yii\sphinx\ColumnSchema, yii\sphinx\Command, yii\sphinx\Connection, yii\sphinx\IndexSchema, yii\sphinx\MatchBuilder, yii\sphinx\MatchExpression, yii\sphinx\Query, yii\sphinx\QueryBuilder, yii\sphinx\Schema, yii\sphinx\gii\model\Generator, yii\swiftmailer\Mailer, yii\swiftmailer\Message, yii\test\ActiveFixture, yii\test\ArrayFixture, yii\test\BaseActiveFixture, yii\test\DbFixture, yii\test\Fixture, yii\test\InitDbFixture, yii\twig\ViewRenderer, yii\validators\BooleanValidator, yii\validators\CompareValidator, yii\validators\DateValidator, yii\validators\DefaultValueValidator, yii\validators\EachValidator, yii\validators\EmailValidator, yii\validators\ExistValidator, yii\validators\FileValidator, yii\validators\FilterValidator, yii\validators\ImageValidator, yii\validators\InlineValidator, yii\validators\IpValidator, yii\validators\NumberValidator, yii\validators\PunycodeAsset, yii\validators\RangeValidator, yii\validators\RegularExpressionValidator, yii\validators\RequiredValidator, yii\validators\SafeValidator, yii\validators\StringValidator, yii\validators\UniqueValidator, yii\validators\UrlValidator, yii\validators\ValidationAsset, yii\validators\Validator, yii\web\Application, yii\web\AssetBundle, yii\web\AssetConverter, yii\web\AssetManager, yii\web\CacheSession, yii\web\CompositeUrlRule, yii\web\Controller, yii\web\Cookie, yii\web\CookieCollection, yii\web\DbSession, yii\web\ErrorAction, yii\web\ErrorHandler, yii\web\GroupUrlRule, yii\web\HeaderCollection, yii\web\HtmlResponseFormatter, yii\web\JqueryAsset, yii\web\JsExpression, yii\web\JsonResponseFormatter, yii\web\Link, yii\web\MultiFieldSession, yii\web\MultipartFormDataParser, yii\web\Request, yii\web\Response, yii\web\Session, yii\web\UploadedFile, yii\web\UrlManager, yii\web\UrlNormalizer, yii\web\UrlRule, yii\web\User, yii\web\UserEvent, yii\web\View, yii\web\ViewAction, yii\web\XmlResponseFormatter, yii\web\YiiAsset, yii\widgets\ActiveField, yii\widgets\ActiveForm, yii\widgets\ActiveFormAsset, yii\widgets\BaseListView, yii\widgets\Block, yii\widgets\Breadcrumbs, yii\widgets\ContentDecorator, yii\widgets\DetailView, yii\widgets\FragmentCache, yii\widgets\InputWidget, yii\widgets\LinkPager, yii\widgets\LinkSorter, yii\widgets\ListView, yii\widgets\MaskedInput, yii\widgets\MaskedInputAsset, yii\widgets\Menu, yii\widgets\Pjax, yii\widgets\PjaxAsset, yii\widgets\Spaceless |
Available since version | 2.0.13 |
Source Code |
https://github.com/yiisoft/yii2/blob/master/framework/base/BaseObject.php |
BaseObject is the base class that implements the property feature.
A property is defined by a getter method (e.g. getLabel
), and/or a setter method (e.g. setLabel
). For example,
the following getter and setter methods define a property named label
:
private $_label;
public function getLabel()
{
return $this->_label;
}
public function setLabel($value)
{
$this->_label = $value;
}
Property names are case-insensitive.
A property can be accessed like a member variable of an object. Reading or writing a property will cause the invocation
of the corresponding getter or setter method. For example,
$label = $object->label;
$object->label = 'abc';
If a property has only a getter method and has no setter method, it is considered as read-only. In this case, trying
to modify the property value will cause an exception.
One can call hasProperty(), canGetProperty() and/or canSetProperty() to check the existence of a property.
Besides the property feature, BaseObject also introduces an important object initialization life cycle. In particular,
creating an new instance of BaseObject or its derived class will involve the following life cycles sequentially:
- the class constructor is invoked;
- object properties are initialized according to the given configuration;
- the
init()
method is invoked.
In the above, both Step 2 and 3 occur at the end of the class constructor. It is recommended that
you perform object initialization in the init()
method because at that stage, the object configuration
is already applied.
In order to ensure the above life cycles, if a child class of BaseObject needs to override the constructor,
it should be done like the following:
public function __construct($param1, $param2, ..., $config = [])
{
...
parent::__construct($config);
}
That is, a $config
parameter (defaults to []
) should be declared as the last parameter
of the constructor, and the parent implementation should be called at the end of the constructor.
Calls the named method which is not a class method.
Do not call this method directly as it is a PHP magic method that
will be implicitly called when an unknown method is being invoked.
Constructor.
The default implementation does two things:
- Initializes the object with the given configuration
$config
.
- Call init().
If this method is overridden in a child class, it is recommended that
- the last parameter of the constructor is a configuration array, like
$config
here.
- call the parent implementation at the end of the constructor.
public void __construct ( $config = [] ) |
$config |
array |
Name-value pairs that will be used to initialize the object properties
|
Returns the value of an object property.
Do not call this method directly as it is a PHP magic method that
will be implicitly called when executing $value = $object->property;
.
See also __set().
Checks if a property is set, i.e. defined and not null.
Do not call this method directly as it is a PHP magic method that
will be implicitly called when executing isset($object->property)
.
Note that if the property is not defined, false will be returned.
See also https://secure.php.net/manual/en/function.isset.php.
public boolean __isset ( $name ) |
$name |
string |
The property name or the event name
|
return |
boolean |
Whether the named property is set (not null).
|
Sets value of an object property.
Do not call this method directly as it is a PHP magic method that
will be implicitly called when executing $object->property = $value;
.
See also __get().
Sets an object property to null.
Do not call this method directly as it is a PHP magic method that
will be implicitly called when executing unset($object->property)
.
Note that if the property is not defined, this method will do nothing.
If the property is read-only, it will throw an exception.
See also https://secure.php.net/manual/en/function.unset.php.
Returns a value indicating whether a property can be read.
A property is readable if:
- the class has a getter method associated with the specified name
(in this case, property name is case-insensitive);
- the class has a member variable with the specified name (when
$checkVars
is true);
See also canSetProperty().
Returns a value indicating whether a property can be set.
A property is writable if:
- the class has a setter method associated with the specified name
(in this case, property name is case-insensitive);
- the class has a member variable with the specified name (when
$checkVars
is true);
See also canGetProperty().
public boolean canSetProperty ( $name, $checkVars = true ) |
$name |
string |
The property name
|
$checkVars |
boolean |
Whether to treat member variables as properties
|
return |
boolean |
Whether the property can be written
|
Deprecated since 2.0.14. On PHP >=5.5, use ::class
instead.
Returns the fully qualified name of this class.
Returns a value indicating whether a method is defined.
The default implementation is a call to php function method_exists()
.
You may override this method when you implemented the php magic method __call()
.
Returns a value indicating whether a property is defined.
A property is defined if:
- the class has a getter or setter method associated with the specified name
(in this case, property name is case-insensitive);
- the class has a member variable with the specified name (when
$checkVars
is true);
See also:
public boolean hasProperty ( $name, $checkVars = true ) |
$name |
string |
The property name
|
$checkVars |
boolean |
Whether to treat member variables as properties
|
return |
boolean |
Whether the property is defined
|
Initializes the object.
This method is invoked at the end of the constructor after the object is initialized with the
given configuration.