新人作业task1

file1.php

<?php
namespace File1 ;

function foo()
{
    echo "Used funection foo!\n" ;
}
?>

file2.php

<?php
namespace File2  ;

class Demo {
   private $simpleVariable ;
   public function __construct( $variable )
   {
      $this->simpleVariable=$variable ;
      echo "A Demo has been constructed! named:".$this->simpleVariable."\n" ;
   }
   public function speak()
   {
       echo $this->simpleVariable ;
   }
}
?>

file3.php

<?php
namespace  File3 ;
const NUMBER=1024 ;
?>

main.php

<?php
require_once ("file1.php") ;
require_once ("file2.php") ;
require_once ("file3.php") ;

use  function File1\foo ;
use  File2\Demo ;
use const File3\NUMBER ;

$demo= new Demo("ZhangChengyi") ;
$demo-> speak() ;
echo NUMBER."\n" ;
foo() ;
?>

运行结果

A Demo has been constructed! named:ZhangChengyi
ZhangChengyi
1024
Used funection foo!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容