Blogger Information
Blog 26
fans 0
comment 0
visits 15786
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
其他空间类的引用,别名引用,自动加载类,数据库的简单操作
庄周梦蝶
Original
494 people have browsed it
  1. 实例演示通过空间引用类的三种方式;

    1. <?php
    2. namespace na1 {
    3. class User
    4. {
    5. }
    6. echo User::class,'<br>';
    7. echo na2\User::class,'<br>';
    8. echo \sss\User::class,'<br>';
    9. }
    10. namespace na1\na2 {
    11. class User
    12. {
    13. }
    14. }
    15. namespace sss {
    16. class User
    17. {
    18. }
    19. }


    2.类的别名引入与命名冲突的解决方案是什么?

    1. <?php
    2. // 这是admin.php文件夹
    3. namespace admin\acc {
    4. class User
    5. {
    6. }
    7. }
    1. <?php
    2. namespace acc {
    3. class User
    4. {
    5. }
    6. require 'admin.php';
    7. use admin\acc\User as adminuser;
    8. $user = new adminUser;
    9. $user1 = new User;
    10. var_dump($user);
    11. echo '<br>';
    12. var_dump($user1);
    13. }


    3.写一个自动加载类;

    1. <?php
    2. //文件地址:app\models\Ass.php
    3. namespace app\models;
    4. class Ass
    5. {
    6. }
    1. <?php
    2. //文件地址:app\models\User.php
    3. namespace app\models;
    4. class User
    5. {
    6. }
    1. <?php
    2. //自动加载文件
    3. spl_autoload_register(function ($class){
    4. $file= str_replace('\\',DIRECTORY_SEPARATOR,$class).'.php';
    5. require $file;
    6. });
    1. <?php
    2. namespace app;
    3. require 'app/loader.php';
    4. use app\models\Ass;
    5. use app\models\User;
    6. $ass=new Ass;
    7. $user=new User;
    8. var_dump($ass, $user);

  2. 将课堂提到的数据库操作命令全部上机做一遍,
  • 1.创建数据库
    create database html collate ;
  • 2.进入数据库并直接选择要修改的数据库
    -mysql -u root -p root html;
  • 3.创建数据表
    create table css (
    id int unsigened auto_increment not null primary key,
    name varchar(20) not null comment ‘姓名’,
    )engine=innodb auto_increment=0 collate=utfomb4_unicode_ci;
  • 4.增加字段
    alter table css add email varchat(150) not null after id ,
  • 5.更新字段
    alter table css change email email varchat(100) not null comment ‘邮箱’ after id,
Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post