美文网首页
新人作业task1

新人作业task1

作者: Bronze_Yi | 来源:发表于2017-09-28 10:56 被阅读0次

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!

相关文章

网友评论

      本文标题:新人作业task1

      本文链接:https://www.haomeiwen.com/subject/bvsmextx.html