From a1c928e3b89813c2ecc382f73170ee703f92dfd4 Mon Sep 17 00:00:00 2001 From: wiwkok-pc <867034892@qq.com> Date: Sun, 20 Mar 2022 21:37:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=91=BD=E5=90=8D=E7=A9=BA=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../02命名空间/01定义命名空间.php | 23 +++++++ .../file1.php | 0 .../file2.php | 0 .../01.php | 14 ++++ .../02.php | 26 +++++++ .../05同一个文件定义多个命名空间 | 69 +++++++++++++++++++ .../02命名空间/06子命名空间.php | 39 +++++++++++ ....php => 10显示当前的命名空间.php} | 0 8 files changed, 171 insertions(+) create mode 100644 07面向对象/02命名空间/01定义命名空间.php rename 07面向对象/02命名空间/{02使用命名空间 => 02-使用命名空间}/file1.php (100%) rename 07面向对象/02命名空间/{02使用命名空间 => 02-使用命名空间}/file2.php (100%) create mode 100644 07面向对象/02命名空间/04多个文件使用同一个命名空间/01.php create mode 100644 07面向对象/02命名空间/04多个文件使用同一个命名空间/02.php create mode 100644 07面向对象/02命名空间/05同一个文件定义多个命名空间 create mode 100644 07面向对象/02命名空间/06子命名空间.php rename 07面向对象/02命名空间/{01显示当前的命名空间.php => 10显示当前的命名空间.php} (100%) diff --git a/07面向对象/02命名空间/01定义命名空间.php b/07面向对象/02命名空间/01定义命名空间.php new file mode 100644 index 0000000..f985582 --- /dev/null +++ b/07面向对象/02命名空间/01定义命名空间.php @@ -0,0 +1,23 @@ +funcA(); +?> \ No newline at end of file diff --git a/07面向对象/02命名空间/02使用命名空间/file1.php b/07面向对象/02命名空间/02-使用命名空间/file1.php similarity index 100% rename from 07面向对象/02命名空间/02使用命名空间/file1.php rename to 07面向对象/02命名空间/02-使用命名空间/file1.php diff --git a/07面向对象/02命名空间/02使用命名空间/file2.php b/07面向对象/02命名空间/02-使用命名空间/file2.php similarity index 100% rename from 07面向对象/02命名空间/02使用命名空间/file2.php rename to 07面向对象/02命名空间/02-使用命名空间/file2.php diff --git a/07面向对象/02命名空间/04多个文件使用同一个命名空间/01.php b/07面向对象/02命名空间/04多个文件使用同一个命名空间/01.php new file mode 100644 index 0000000..f0f16c4 --- /dev/null +++ b/07面向对象/02命名空间/04多个文件使用同一个命名空间/01.php @@ -0,0 +1,14 @@ + \ No newline at end of file diff --git a/07面向对象/02命名空间/04多个文件使用同一个命名空间/02.php b/07面向对象/02命名空间/04多个文件使用同一个命名空间/02.php new file mode 100644 index 0000000..ce10174 --- /dev/null +++ b/07面向对象/02命名空间/04多个文件使用同一个命名空间/02.php @@ -0,0 +1,26 @@ +var.PHP_EOL; + + echo $var1; + + /** + * 在02.php中使用01.php的命名空间,需要include"01.php" + * 说明01.php中的namespace Project1的作用范围就是01.php内 + * 虽然02.php的命名空间也是Project1,但如果要使用其实文件中的命名空间,还是需要inlcude + */ +?> \ No newline at end of file diff --git a/07面向对象/02命名空间/05同一个文件定义多个命名空间 b/07面向对象/02命名空间/05同一个文件定义多个命名空间 new file mode 100644 index 0000000..b84dfd5 --- /dev/null +++ b/07面向对象/02命名空间/05同一个文件定义多个命名空间 @@ -0,0 +1,69 @@ +fnA(); + } + + namespace Tom + { + $varA=__NAMESPACE__; + + const content="这个一个常量"; + + function fnA(){ + echo __NAMESPACE__.__FUNCTION__.PHP_EOL; + } + + class ClassA{ + public $varA=2; + + public function fnA(){ + echo __NAMESPACE__.__FUNCTION__.PHP_EOL; + } + } + + echo $varA.PHP_EOL; + + fnA(); + + $obj=new ClassA; + $obj->fnA(); + } + + //全局代码 + namespace{ + $varA="全局代码中的变量"; + echo $varA.PHP_EOL; + + //调用其中一个命名 + // echo Jack\$varA.PHP_EOL; //变量不在命名空间的作用范围内 + echo Jack\constA; //常量 + Jack\fnA(); //函数 + $objA=new Jack\ClassA; //类 + echo $objA->varA.PHP_EOL; + + //echo Tom\$varA.PHP_EOL; + } + +?> \ No newline at end of file diff --git a/07面向对象/02命名空间/06子命名空间.php b/07面向对象/02命名空间/06子命名空间.php new file mode 100644 index 0000000..3d72294 --- /dev/null +++ b/07面向对象/02命名空间/06子命名空间.php @@ -0,0 +1,39 @@ + \ No newline at end of file diff --git a/07面向对象/02命名空间/01显示当前的命名空间.php b/07面向对象/02命名空间/10显示当前的命名空间.php similarity index 100% rename from 07面向对象/02命名空间/01显示当前的命名空间.php rename to 07面向对象/02命名空间/10显示当前的命名空间.php