|
- <?php
-
-
- namespace yii\db;
-
- use yii\base\InvalidConfigException;
- use yii\base\Event;
- use yii\base\Model;
- use yii\base\InvalidParamException;
- use yii\base\ModelEvent;
- use yii\base\NotSupportedException;
- use yii\base\UnknownMethodException;
- use yii\base\InvalidCallException;
- use yii\helpers\ArrayHelper;
-
-
- abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
- {
-
-
- const EVENT_INIT = 'init';
-
-
- const EVENT_AFTER_FIND = 'afterFind';
-
-
- const EVENT_BEFORE_INSERT = 'beforeInsert';
-
-
- const EVENT_AFTER_INSERT = 'afterInsert';
-
-
- const EVENT_BEFORE_UPDATE = 'beforeUpdate';
-
-
- const EVENT_AFTER_UPDATE = 'afterUpdate';
-
-
- const EVENT_BEFORE_DELETE = 'beforeDelete';
-
-
- const EVENT_AFTER_DELETE = 'afterDelete';
-
-
- const EVENT_AFTER_REFRESH = 'afterRefresh';
-
-
-
- private $_attributes = [];
-
-
- private $_oldAttributes;
-
-
- private $_related = [];
-
-
-
-
- public static function findOne($condition)
- {
- return static::findByCondition($condition)->one();
- }
-
-
-
- public static function findAll($condition)
- {
- return static::findByCondition($condition)->all();
- }
-
-
-
- protected static function findByCondition($condition)
- {
- $query = static::find();
-
- if (!ArrayHelper::isAssociative($condition)) {
-
- $primaryKey = static::primaryKey();
- if (isset($primaryKey[0])) {
- $condition = [$primaryKey[0] => $condition];
- } else {
- throw new InvalidConfigException('"' . get_called_class() . '" must have a primary key.');
- }
- }
-
- return $query->andWhere($condition);
- }
-
-
-
- public static function updateAll($attributes, $condition = '')
- {
- throw new NotSupportedException(__METHOD__ . ' is not supported.');
- }
-
-
-
- public static function updateAllCounters($counters, $condition = '')
- {
- throw new NotSupportedException(__METHOD__ . ' is not supported.');
- }
-
-
-
- public static function deleteAll($condition = '', $params = [])
- {
- throw new NotSupportedException(__METHOD__ . ' is not supported.');
- }
-
-
-
- public function optimisticLock()
- {
- return null;
- }
-
-
-
- public function canGetProperty($name, $checkVars = true, $checkBehaviors = true)
- {
- if (parent::canGetProperty($name, $checkVars, $checkBehaviors)) {
- return true;
- }
-
- try {
- return $this->hasAttribute($name);
- } catch (\Exception $e) {
-
- return false;
- }
- }
-
-
-
- public function canSetProperty($name, $checkVars = true, $checkBehaviors = true)
- {
- if (parent::canSetProperty($name, $checkVars, $checkBehaviors)) {
- return true;
- }
-
- try {
- return $this->hasAttribute($name);
- } catch (\Exception $e) {
-
- return false;
- }
- }
-
-
-
- public function __get($name)
- {
- if (isset($this->_attributes[$name]) || array_key_exists($name, $this->_attributes)) {
- return $this->_attributes[$name];
- } elseif ($this->hasAttribute($name)) {
- return null;
- } else {
- if (isset($this->_related[$name]) || array_key_exists($name, $this->_related)) {
- return $this->_related[$name];
- }
- $value = parent::__get($name);
- if ($value instanceof ActiveQueryInterface) {
- return $this->_related[$name] = $value->findFor($name, $this);
- } else {
- return $value;
- }
- }
- }
-
-
-
- public function __set($name, $value)
- {
- if ($this->hasAttribute($name)) {
- $this->_attributes[$name] = $value;
- } else {
- parent::__set($name, $value);
- }
- }
-
-
-
- public function __isset($name)
- {
- try {
- return $this->__get($name) !== null;
- } catch (\Exception $e) {
- return false;
- }
- }
-
-
-
- public function __unset($name)
- {
- if ($this->hasAttribute($name)) {
- unset($this->_attributes[$name]);
- } elseif (array_key_exists($name, $this->_related)) {
- unset($this->_related[$name]);
- } elseif ($this->getRelation($name, false) === null) {
- parent::__unset($name);
- }
- }
-
-
-
- public function hasOne($class, $link)
- {
-
-
- $query = $class::find();
- $query->primaryModel = $this;
- $query->link = $link;
- $query->multiple = false;
- return $query;
- }
-
-
-
- public function hasMany($class, $link)
- {
-
-
- $query = $class::find();
- $query->primaryModel = $this;
- $query->link = $link;
- $query->multiple = true;
- return $query;
- }
-
-
-
- public function populateRelation($name, $records)
- {
- $this->_related[$name] = $records;
- }
-
-
-
- public function isRelationPopulated($name)
- {
- return array_key_exists($name, $this->_related);
- }
-
-
-
- public function getRelatedRecords()
- {
- return $this->_related;
- }
-
-
-
- public function hasAttribute($name)
- {
- return isset($this->_attributes[$name]) || in_array($name, $this->attributes(), true);
- }
-
-
-
- public function getAttribute($name)
- {
- return isset($this->_attributes[$name]) ? $this->_attributes[$name] : null;
- }
-
-
-
- public function setAttribute($name, $value)
- {
- if ($this->hasAttribute($name)) {
- $this->_attributes[$name] = $value;
- } else {
- throw new InvalidParamException(get_class($this) . ' has no attribute named "' . $name . '".');
- }
- }
-
-
-
- public function getOldAttributes()
- {
- return $this->_oldAttributes === null ? [] : $this->_oldAttributes;
- }
-
-
-
- public function setOldAttributes($values)
- {
- $this->_oldAttributes = $values;
- }
-
-
-
- public function getOldAttribute($name)
- {
- return isset($this->_oldAttributes[$name]) ? $this->_oldAttributes[$name] : null;
- }
-
-
-
- public function setOldAttribute($name, $value)
- {
- if (isset($this->_oldAttributes[$name]) || $this->hasAttribute($name)) {
- $this->_oldAttributes[$name] = $value;
- } else {
- throw new InvalidParamException(get_class($this) . ' has no attribute named "' . $name . '".');
- }
- }
-
-
-
- public function markAttributeDirty($name)
- {
- unset($this->_oldAttributes[$name]);
- }
-
-
-
- public function isAttributeChanged($name, $identical = true)
- {
- if (isset($this->_attributes[$name], $this->_oldAttributes[$name])) {
- if ($identical) {
- return $this->_attributes[$name] !== $this->_oldAttributes[$name];
- } else {
- return $this->_attributes[$name] != $this->_oldAttributes[$name];
- }
- } else {
- return isset($this->_attributes[$name]) || isset($this->_oldAttributes[$name]);
- }
- }
-
-
-
- public function getDirtyAttributes($names = null)
- {
- if ($names === null) {
- $names = $this->attributes();
- }
- $names = array_flip($names);
- $attributes = [];
- if ($this->_oldAttributes === null) {
- foreach ($this->_attributes as $name => $value) {
- if (isset($names[$name])) {
- $attributes[$name] = $value;
- }
- }
- } else {
- foreach ($this->_attributes as $name => $value) {
- if (isset($names[$name]) && (!array_key_exists($name, $this->_oldAttributes) || $value !== $this->_oldAttributes[$name])) {
- $attributes[$name] = $value;
- }
- }
- }
- return $attributes;
- }
-
-
-
- public function save($runValidation = true, $attributeNames = null)
- {
- if ($this->getIsNewRecord()) {
- return $this->insert($runValidation, $attributeNames);
- } else {
- return $this->update($runValidation, $attributeNames) !== false;
- }
- }
-
-
-
- public function update($runValidation = true, $attributeNames = null)
- {
- if ($runValidation && !$this->validate($attributeNames)) {
- return false;
- }
- return $this->updateInternal($attributeNames);
- }
-
-
-
- public function updateAttributes($attributes)
- {
- $attrs = [];
- foreach ($attributes as $name => $value) {
- if (is_int($name)) {
- $attrs[] = $value;
- } else {
- $this->$name = $value;
- $attrs[] = $name;
- }
- }
-
- $values = $this->getDirtyAttributes($attrs);
- if (empty($values) || $this->getIsNewRecord()) {
- return 0;
- }
-
- $rows = static::updateAll($values, $this->getOldPrimaryKey(true));
-
- foreach ($values as $name => $value) {
- $this->_oldAttributes[$name] = $this->_attributes[$name];
- }
-
- return $rows;
- }
-
-
-
- protected function updateInternal($attributes = null)
- {
- if (!$this->beforeSave(false)) {
- return false;
- }
- $values = $this->getDirtyAttributes($attributes);
- if (empty($values)) {
- $this->afterSave(false, $values);
- return 0;
- }
- $condition = $this->getOldPrimaryKey(true);
- $lock = $this->optimisticLock();
- if ($lock !== null) {
- $values[$lock] = $this->$lock + 1;
- $condition[$lock] = $this->$lock;
- }
-
-
- $rows = static::updateAll($values, $condition);
-
- if ($lock !== null && !$rows) {
- throw new StaleObjectException('The object being updated is outdated.');
- }
-
- if (isset($values[$lock])) {
- $this->$lock = $values[$lock];
- }
-
- $changedAttributes = [];
- foreach ($values as $name => $value) {
- $changedAttributes[$name] = isset($this->_oldAttributes[$name]) ? $this->_oldAttributes[$name] : null;
- $this->_oldAttributes[$name] = $value;
- }
- $this->afterSave(false, $changedAttributes);
-
- return $rows;
- }
-
-
-
- public function updateCounters($counters)
- {
- if (static::updateAllCounters($counters, $this->getOldPrimaryKey(true)) > 0) {
- foreach ($counters as $name => $value) {
- if (!isset($this->_attributes[$name])) {
- $this->_attributes[$name] = $value;
- } else {
- $this->_attributes[$name] += $value;
- }
- $this->_oldAttributes[$name] = $this->_attributes[$name];
- }
- return true;
- } else {
- return false;
- }
- }
-
-
-
- public function delete()
- {
- $result = false;
- if ($this->beforeDelete()) {
-
-
- $condition = $this->getOldPrimaryKey(true);
- $lock = $this->optimisticLock();
- if ($lock !== null) {
- $condition[$lock] = $this->$lock;
- }
- $result = static::deleteAll($condition);
- if ($lock !== null && !$result) {
- throw new StaleObjectException('The object being deleted is outdated.');
- }
- $this->_oldAttributes = null;
- $this->afterDelete();
- }
-
- return $result;
- }
-
-
-
- public function getIsNewRecord()
- {
- return $this->_oldAttributes === null;
- }
-
-
-
- public function setIsNewRecord($value)
- {
- $this->_oldAttributes = $value ? null : $this->_attributes;
- }
-
-
-
- public function init()
- {
- parent::init();
- $this->trigger(self::EVENT_INIT);
- }
-
-
-
- public function afterFind()
- {
- $this->trigger(self::EVENT_AFTER_FIND);
- }
-
-
-
- public function beforeSave($insert)
- {
- $event = new ModelEvent;
- $this->trigger($insert ? self::EVENT_BEFORE_INSERT : self::EVENT_BEFORE_UPDATE, $event);
-
- return $event->isValid;
- }
-
-
-
- public function afterSave($insert, $changedAttributes)
- {
- $this->trigger($insert ? self::EVENT_AFTER_INSERT : self::EVENT_AFTER_UPDATE, new AfterSaveEvent([
- 'changedAttributes' => $changedAttributes,
- ]));
- }
-
-
-
- public function beforeDelete()
- {
- $event = new ModelEvent;
- $this->trigger(self::EVENT_BEFORE_DELETE, $event);
-
- return $event->isValid;
- }
-
-
-
- public function afterDelete()
- {
- $this->trigger(self::EVENT_AFTER_DELETE);
- }
-
-
-
- public function refresh()
- {
-
- $record = static::findOne($this->getPrimaryKey(true));
- if ($record === null) {
- return false;
- }
- foreach ($this->attributes() as $name) {
- $this->_attributes[$name] = isset($record->_attributes[$name]) ? $record->_attributes[$name] : null;
- }
- $this->_oldAttributes = $record->_oldAttributes;
- $this->_related = [];
- $this->afterRefresh();
-
- return true;
- }
-
-
-
- public function afterRefresh()
- {
- $this->trigger(self::EVENT_AFTER_REFRESH);
- }
-
-
-
- public function equals($record)
- {
- if ($this->getIsNewRecord() || $record->getIsNewRecord()) {
- return false;
- }
-
- return get_class($this) === get_class($record) && $this->getPrimaryKey() === $record->getPrimaryKey();
- }
-
-
-
- public function getPrimaryKey($asArray = false)
- {
- $keys = $this->primaryKey();
- if (!$asArray && count($keys) === 1) {
- return isset($this->_attributes[$keys[0]]) ? $this->_attributes[$keys[0]] : null;
- } else {
- $values = [];
- foreach ($keys as $name) {
- $values[$name] = isset($this->_attributes[$name]) ? $this->_attributes[$name] : null;
- }
-
- return $values;
- }
- }
-
-
-
- public function getOldPrimaryKey($asArray = false)
- {
- $keys = $this->primaryKey();
- if (empty($keys)) {
- throw new Exception(get_class($this) . ' does not have a primary key. You should either define a primary key for the corresponding table or override the primaryKey() method.');
- }
- if (!$asArray && count($keys) === 1) {
- return isset($this->_oldAttributes[$keys[0]]) ? $this->_oldAttributes[$keys[0]] : null;
- } else {
- $values = [];
- foreach ($keys as $name) {
- $values[$name] = isset($this->_oldAttributes[$name]) ? $this->_oldAttributes[$name] : null;
- }
-
- return $values;
- }
- }
-
-
-
- public static function populateRecord($record, $row)
- {
- $columns = array_flip($record->attributes());
- foreach ($row as $name => $value) {
- if (isset($columns[$name])) {
- $record->_attributes[$name] = $value;
- } elseif ($record->canSetProperty($name)) {
- $record->$name = $value;
- }
- }
- $record->_oldAttributes = $record->_attributes;
- }
-
-
-
- public static function instantiate($row)
- {
- return new static;
- }
-
-
-
- public function offsetExists($offset)
- {
- return $this->__isset($offset);
- }
-
-
-
- public function getRelation($name, $throwException = true)
- {
- $getter = 'get' . $name;
- try {
-
- $relation = $this->$getter();
- } catch (UnknownMethodException $e) {
- if ($throwException) {
- throw new InvalidParamException(get_class($this) . ' has no relation named "' . $name . '".', 0, $e);
- } else {
- return null;
- }
- }
- if (!$relation instanceof ActiveQueryInterface) {
- if ($throwException) {
- throw new InvalidParamException(get_class($this) . ' has no relation named "' . $name . '".');
- } else {
- return null;
- }
- }
-
- if (method_exists($this, $getter)) {
-
- $method = new \ReflectionMethod($this, $getter);
- $realName = lcfirst(substr($method->getName(), 3));
- if ($realName !== $name) {
- if ($throwException) {
- throw new InvalidParamException('Relation names are case sensitive. ' . get_class($this) . " has a relation named \"$realName\" instead of \"$name\".");
- } else {
- return null;
- }
- }
- }
-
- return $relation;
- }
-
-
-
- public function link($name, $model, $extraColumns = [])
- {
- $relation = $this->getRelation($name);
-
- if ($relation->via !== null) {
- if ($this->getIsNewRecord() || $model->getIsNewRecord()) {
- throw new InvalidCallException('Unable to link models: the models being linked cannot be newly created.');
- }
- if (is_array($relation->via)) {
-
- list($viaName, $viaRelation) = $relation->via;
- $viaClass = $viaRelation->modelClass;
-
- unset($this->_related[$viaName]);
- } else {
- $viaRelation = $relation->via;
- $viaTable = reset($relation->via->from);
- }
- $columns = [];
- foreach ($viaRelation->link as $a => $b) {
- $columns[$a] = $this->$b;
- }
- foreach ($relation->link as $a => $b) {
- $columns[$b] = $model->$a;
- }
- foreach ($extraColumns as $k => $v) {
- $columns[$k] = $v;
- }
- if (is_array($relation->via)) {
-
-
- $record = new $viaClass();
- foreach ($columns as $column => $value) {
- $record->$column = $value;
- }
- $record->insert(false);
- } else {
-
- static::getDb()->createCommand()
- ->insert($viaTable, $columns)->execute();
- }
- } else {
- $p1 = $model->isPrimaryKey(array_keys($relation->link));
- $p2 = static::isPrimaryKey(array_values($relation->link));
- if ($p1 && $p2) {
- if ($this->getIsNewRecord() && $model->getIsNewRecord()) {
- throw new InvalidCallException('Unable to link models: at most one model can be newly created.');
- } elseif ($this->getIsNewRecord()) {
- $this->bindModels(array_flip($relation->link), $this, $model);
- } else {
- $this->bindModels($relation->link, $model, $this);
- }
- } elseif ($p1) {
- $this->bindModels(array_flip($relation->link), $this, $model);
- } elseif ($p2) {
- $this->bindModels($relation->link, $model, $this);
- } else {
- throw new InvalidCallException('Unable to link models: the link defining the relation does not involve any primary key.');
- }
- }
-
-
- if (!$relation->multiple) {
- $this->_related[$name] = $model;
- } elseif (isset($this->_related[$name])) {
- if ($relation->indexBy !== null) {
- if ($relation->indexBy instanceof \Closure) {
- $index = call_user_func($relation->indexBy, $model);
- } else {
- $index = $model->{$relation->indexBy};
- }
- $this->_related[$name][$index] = $model;
- } else {
- $this->_related[$name][] = $model;
- }
- }
- }
-
-
-
- public function unlink($name, $model, $delete = false)
- {
- $relation = $this->getRelation($name);
-
- if ($relation->via !== null) {
- if (is_array($relation->via)) {
-
- list($viaName, $viaRelation) = $relation->via;
- $viaClass = $viaRelation->modelClass;
- unset($this->_related[$viaName]);
- } else {
- $viaRelation = $relation->via;
- $viaTable = reset($relation->via->from);
- }
- $columns = [];
- foreach ($viaRelation->link as $a => $b) {
- $columns[$a] = $this->$b;
- }
- foreach ($relation->link as $a => $b) {
- $columns[$b] = $model->$a;
- }
- $nulls = [];
- foreach (array_keys($columns) as $a) {
- $nulls[$a] = null;
- }
- if (is_array($relation->via)) {
-
- if ($delete) {
- $viaClass::deleteAll($columns);
- } else {
- $viaClass::updateAll($nulls, $columns);
- }
- } else {
-
-
- $command = static::getDb()->createCommand();
- if ($delete) {
- $command->delete($viaTable, $columns)->execute();
- } else {
- $command->update($viaTable, $nulls, $columns)->execute();
- }
- }
- } else {
- $p1 = $model->isPrimaryKey(array_keys($relation->link));
- $p2 = static::isPrimaryKey(array_values($relation->link));
- if ($p2) {
- if ($delete) {
- $model->delete();
- } else {
- foreach ($relation->link as $a => $b) {
- $model->$a = null;
- }
- $model->save(false);
- }
- } elseif ($p1) {
- foreach ($relation->link as $a => $b) {
- if (is_array($this->$b)) {
- if (($key = array_search($model->$a, $this->$b, false)) !== false) {
- $values = $this->$b;
- unset($values[$key]);
- $this->$b = array_values($values);
- }
- } else {
- $this->$b = null;
- }
- }
- $delete ? $this->delete() : $this->save(false);
- } else {
- throw new InvalidCallException('Unable to unlink models: the link does not involve any primary key.');
- }
- }
-
- if (!$relation->multiple) {
- unset($this->_related[$name]);
- } elseif (isset($this->_related[$name])) {
-
- foreach ($this->_related[$name] as $a => $b) {
- if ($model->getPrimaryKey() === $b->getPrimaryKey()) {
- unset($this->_related[$name][$a]);
- }
- }
- }
- }
-
-
-
- public function unlinkAll($name, $delete = false)
- {
- $relation = $this->getRelation($name);
-
- if ($relation->via !== null) {
- if (is_array($relation->via)) {
-
- list($viaName, $viaRelation) = $relation->via;
- $viaClass = $viaRelation->modelClass;
- unset($this->_related[$viaName]);
- } else {
- $viaRelation = $relation->via;
- $viaTable = reset($relation->via->from);
- }
- $condition = [];
- $nulls = [];
- foreach ($viaRelation->link as $a => $b) {
- $nulls[$a] = null;
- $condition[$a] = $this->$b;
- }
- if (!empty($viaRelation->where)) {
- $condition = ['and', $condition, $viaRelation->where];
- }
- if (is_array($relation->via)) {
-
- if ($delete) {
- $viaClass::deleteAll($condition);
- } else {
- $viaClass::updateAll($nulls, $condition);
- }
- } else {
-
-
- $command = static::getDb()->createCommand();
- if ($delete) {
- $command->delete($viaTable, $condition)->execute();
- } else {
- $command->update($viaTable, $nulls, $condition)->execute();
- }
- }
- } else {
-
- $relatedModel = $relation->modelClass;
- if (!$delete && count($relation->link) === 1 && is_array($this->{$b = reset($relation->link)})) {
-
- $this->$b = [];
- $this->save(false);
- } else {
- $nulls = [];
- $condition = [];
- foreach ($relation->link as $a => $b) {
- $nulls[$a] = null;
- $condition[$a] = $this->$b;
- }
- if (!empty($relation->where)) {
- $condition = ['and', $condition, $relation->where];
- }
- if ($delete) {
- $relatedModel::deleteAll($condition);
- } else {
- $relatedModel::updateAll($nulls, $condition);
- }
- }
- }
-
- unset($this->_related[$name]);
- }
-
-
-
- private function bindModels($link, $foreignModel, $primaryModel)
- {
- foreach ($link as $fk => $pk) {
- $value = $primaryModel->$pk;
- if ($value === null) {
- throw new InvalidCallException('Unable to link models: the primary key of ' . get_class($primaryModel) . ' is null.');
- }
- if (is_array($foreignModel->$fk)) {
- $foreignModel->$fk = array_merge($foreignModel->$fk, [$value]);
- } else {
- $foreignModel->$fk = $value;
- }
- }
- $foreignModel->save(false);
- }
-
-
-
- public static function isPrimaryKey($keys)
- {
- $pks = static::primaryKey();
- if (count($keys) === count($pks)) {
- return count(array_intersect($keys, $pks)) === count($pks);
- } else {
- return false;
- }
- }
-
-
-
- public function getAttributeLabel($attribute)
- {
- $labels = $this->attributeLabels();
- if (isset($labels[$attribute])) {
- return $labels[$attribute];
- } elseif (strpos($attribute, '.')) {
- $attributeParts = explode('.', $attribute);
- $neededAttribute = array_pop($attributeParts);
-
- $relatedModel = $this;
- foreach ($attributeParts as $relationName) {
- if ($relatedModel->isRelationPopulated($relationName) && $relatedModel->$relationName instanceof self) {
- $relatedModel = $relatedModel->$relationName;
- } else {
- try {
- $relation = $relatedModel->getRelation($relationName);
- } catch (InvalidParamException $e) {
- return $this->generateAttributeLabel($attribute);
- }
- $relatedModel = new $relation->modelClass;
- }
- }
-
- $labels = $relatedModel->attributeLabels();
- if (isset($labels[$neededAttribute])) {
- return $labels[$neededAttribute];
- }
- }
-
- return $this->generateAttributeLabel($attribute);
- }
-
-
-
- public function getAttributeHint($attribute)
- {
- $hints = $this->attributeHints();
- if (isset($hints[$attribute])) {
- return $hints[$attribute];
- } elseif (strpos($attribute, '.')) {
- $attributeParts = explode('.', $attribute);
- $neededAttribute = array_pop($attributeParts);
-
- $relatedModel = $this;
- foreach ($attributeParts as $relationName) {
- if ($relatedModel->isRelationPopulated($relationName) && $relatedModel->$relationName instanceof self) {
- $relatedModel = $relatedModel->$relationName;
- } else {
- try {
- $relation = $relatedModel->getRelation($relationName);
- } catch (InvalidParamException $e) {
- return '';
- }
- $relatedModel = new $relation->modelClass;
- }
- }
-
- $hints = $relatedModel->attributeHints();
- if (isset($hints[$neededAttribute])) {
- return $hints[$neededAttribute];
- }
- }
- return '';
- }
-
-
-
- public function fields()
- {
- $fields = array_keys($this->_attributes);
-
- return array_combine($fields, $fields);
- }
-
-
-
- public function extraFields()
- {
- $fields = array_keys($this->getRelatedRecords());
-
- return array_combine($fields, $fields);
- }
-
-
-
- public function offsetUnset($offset)
- {
- if (property_exists($this, $offset)) {
- $this->$offset = null;
- } else {
- unset($this->$offset);
- }
- }
- }
|