Blogger Information
Blog 25
fans 0
comment 0
visits 15862
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
0802自动加载
杨发国的博客
Original
777 people have browsed it

自动加载

实例

文件jz.php

<?php
namespace _0802;

//require __DIR__.'/inc/Test1.php';
//require __DIR__.'/inc/Test2.php';
//echo  \inc\Test1::get().'<br>';
//echo  \inc\Test2::get().'<br>';

spl_autoload_register(function ($ClassName){
$path=str_replace('//','/',$ClassName);
$path=__DIR__.'\\'.$path.'.php';
if(file_exists( $path)){
    require $path;
}
});

echo  \inc\Test1::get();
echo '<br>';
echo  \inc\Test2::get();

运行实例 »

点击 "运行实例" 按钮查看在线实例

Test1.php

实例

<?php

namespace inc;


class Test1
{
public static function get()
{
    return  __CLASS__.'被加载成功';
}
}

运行实例 »

点击 "运行实例" 按钮查看在线实例

Test2.php

实例

<?php

namespace inc;
class Test2
{
public static function get()
{
    return  __CLASS__.'被加载成功';
}
}

运行实例 »

点击 "运行实例" 按钮查看在线实例

1.png

 

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