Yii2 Framework Essay 18

Source: Internet
Author: User

<?PHP/** * Sets value of a object property.     * Set the property value of the object. * Do not call the This method directly as it's a PHP magic method that * would be implicitly called when executing ' $OBJEC     T->property = $value; '. * * Magic method, implement Setter * * @param string $name The property name or the event name * @param mixed $value the P Roperty value * @throws unknownpropertyexception if the property was not defined * @throws invalidcallexception if The property is Read-only * @see __get ()*/     Publicfunction __set ($name, $value) {$setter='Set'. $name; if(Method_exists ($ This, $setter)) {            //object exists $setter method, it is called directly$ This-$setter ($value); } elseif (Method_exists ($ This,'Get'. $name)) {            //If there is a ' get '. $name method, the property is considered read-only            Throw NewInvalidcallexception ('Setting read-only Property:'. Get_class ($ This) .'::'. $name); } Else {            //Otherwise, the attribute is not considered to exist            Throw NewUnknownpropertyexception ('Setting Unknown Property:'. Get_class ($ This) .'::'. $name); }    }     /** * Checks If the named property was set (NOT null). * Check if the property is set * * Does not call the This method directly as it is a PHP magic method which * will be implicitly called     When executing ' isset ($object->property) '.     * Do not call this method directly, because it is a PHP magic method, call execution ' Isset ($object->property) '.     * Note If the property is not defined, false would be returned.     * * Magic method, implement Isset, based on getter implementation, the property of getter method is counted to exist * * @param string $name The properties name or the event name     * @return Boolean whether the named property is set (NOT null). */     Publicfunction __isset ($name) {$getter='Get'. $name; if(Method_exists ($ This, $getter)) {            //There is a $getter method and the obtained value is not null before the attribute is considered to exist            return$ This$getter ()!==NULL; } Else {            return false; }    }    /** * Sets an object property to null. * Don't call the This method directly as it's a PHP magic method that * would be implicitly called when executing '     unset ($object->property) '.     * Do not call this method directly, because it is a PHP magic method, call execution ' Isset ($object->property) '.     * Note If the property was not a defined, this method would do nothing.     * If The property is read-only, it'll throw an exception. * * Magic method, implement unset, based on setter implementation, with setter method properties to unset out * * @param string $name The property name * @throw     S Invalidcallexception if the property was read only. */     Publicfunction __unset ($name) {$setter='Set'. $name; if(Method_exists ($ This, $setter)) {            //set it to null by $setter method$ This$setter (NULL); } elseif (Method_exists ($ This,'Get'. $name)) {            //If there is a ' get '. $name method, the property is considered read-only            Throw NewInvalidcallexception ('unsetting read-only Property:'. Get_class ($ This) .'::'. $name); }    }    /** * Calls the named method which is not a class method. * Don't call the This method directly as it's a PHP magic method that * would be implicitly called if an unknown     method is being invoked. * Override the __call () method, call this method when calling a non-existent method, throw an exception * @param string $name The method name * @param array $params method paramete RS * @throws unknownmethodexception when calling unknown method * @return Mixed the method return value*/     Publicfunction __call ($name, $params)    {        Throw NewUnknownmethodexception ('calling unknown method:'. Get_class ($ This) . ":: $name ()"); }    /** * Returns A value indicating whether a property is defined.     * Returns a value indicating whether the attribute is defined.    * A property is defined if: * *-the class have A getter or setter method associated with the specified name *     (The property name is case-insensitive);     *-The class has a member variable with the specified name (when ' $checkVars ' is true);     * * Check whether an object or class has a $name property, and if $checkVars is true, it is not limited to whether there is a getter/setter * * @param string $name the name  * @param boolean $checkVars whether to treat member variables as properties * @return Boolean whether the property is defined * @see cangetproperty () * @see Cansetproperty ()*/     Publicfunction Hasproperty ($name, $checkVars =true)    {        return$ This->cangetproperty ($name, $checkVars) | | $ This->cansetproperty ($name,false); }    /** * Returns A value indicating whether a property can be read. * A property is readable if: * *-the class have A getter method associated with the specified name * (in th     is case, property name is case-insensitive);     *-The class has a member variable with the specified name (when ' $checkVars ' is true);  * * Check whether the object or class can get $name property, if $checkVars is true, is not limited to whether there is a getter * * @param string $name the name * @param boolean $checkVars whether to treat member variables as properties * @return Boolean whether the property can Be read * @see Cansetproperty ()

Yii2 Framework Essay 18

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.