Using use and not using use in PHP

Source: Internet
Author: User
Cases:

phpnamespace common\models;use yii\behaviors\TimestampBehavior;class User extends \yii\db\ActiveRecord implements IdentityInterface{public function behaviors()    {        return [            TimestampBehavior::className(),        ];    }}

And

phpnamespace common\models;class User extends \yii\db\ActiveRecord implements IdentityInterface{public function behaviors()    {        return [            \yii\behaviors\TimestampBehavior::className(),        ];    }}

What difference does it have? For example, the following will be used in the time to ... And the above one whether or not used are ... (Purely 自己YY )
P.S: If you step on my question, please give reasons, thanks (rest assured, I am not a squirt)

Reply content:

Cases:

phpnamespace common\models;use yii\behaviors\TimestampBehavior;class User extends \yii\db\ActiveRecord implements IdentityInterface{public function behaviors()    {        return [            TimestampBehavior::className(),        ];    }}

And

phpnamespace common\models;class User extends \yii\db\ActiveRecord implements IdentityInterface{public function behaviors()    {        return [            \yii\behaviors\TimestampBehavior::className(),        ];    }}

What difference does it have? For example, the following will be used in the time to ... And the above one whether or not used are ... (Purely 自己YY )
P.S: If you step on my question, please give reasons, thanks (rest assured, I am not a squirt)

Use only declares the location of the file that will be used later, and does not have a reference, but only when the call is loaded.
It is recommended to use the first method, and the file will be readable in the beginning.

Agree @ Sandy's big point of view, using the use of only just release the variables within the namespace, easy to write only, you can refer to my answer to read more: http://segmentfault.com/q/1010000002544855/a-1020000002544893

  • 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.