【发布时间】:2014-02-27 00:14:32
【问题描述】:
使用相同的命名空间 php
我在同一个文件夹中有这些文件:
OtherFunctions.php
<?php
namespace Pack\sp;
$Tble = NULL;
function SetTble($tble) {
global $Tble;
$Tble = $tble;
}
function GetTble() {
global $Tble;
return $Tble;
}
function Funct0($Str0, $Str1) {
return $Str0 == $Str1;
}
function Funct1($Arg) {
return "The Value is ".$Arg;
}
//... from 0 to 16
function Funct16($Arg) {
return "The Value is ".$Arg;
}
?>
如何调用该文件中包含的所有函数?
在一个类文件 SubClass.php 我有这个:
<?php
namespace Pack\sp;
class SubClass {
public $CArg = "";
}
?>
在其他类文件LeadClass.php 我有这个:
<?php
namespace Pack\sp;
use \Pack\sp\SubClass;
require_once("OtherFunctions.php");
class LeadClass {
public function __construct($Name) {
echo("_._");
$NewSC = new SubClass();
$NewSC->CArg = $Name;
SetTble($Name);
echo("ini:".GetTble().":end");
}
}
?>
我想在OtherFunctions.php文件的一条指令中调用所有函数,但我不知道怎么做......
我试图在其他代码中复制此消息 致命错误:在第 10 行调用 C:...\LeadClass.php 中未定义的函数 GetTble()
但是,我得到的是空白页
编辑
被添加的行:
require_once("OtherFunctions.php");
并被换行:
require_once("SubClass.php");
按行:
use \Pack\sp\SubClass;
在 LeadClass.php 文件中。
但是,我得到的是空白页
【问题讨论】:
标签: php class namespaces undefined