Home > Backend Development > PHP Tutorial > 一个PHP命名空间的有关问题.很无语的有关问题.

一个PHP命名空间的有关问题.很无语的有关问题.

WBOY
Release: 2016-06-13 12:06:45
Original
848 people have browsed it

一个PHP命名空间的问题....很无语的问题.....
  直接上点小代码


<br /><?php<br />//用来定义一个继承Smarty的子类,在构造函数中实现基本的路径配置.....<br />namespace Smarty;<br /><br />class Smarty_Test  {<br />    function setName(){<br />    	echo 'Name';<br />    }<br />}<br />
Copy after login


<br /><?php<br />use Smarty\Smarty_Test;<br /><br />$smarty = new Smarty_Test();<br />$smarty->assign('name','Ned');<br />$smarty->debugging = true;<br />$smarty->display('index.tpl');<br />?><br />
Copy after login


代码如上,很简单,两段代码的文件结构在同一个目录下

就这样,运行死活说找不到类..........
Fatal error: Class 'Smarty\Smarty_Test' not found in ............
实在是没搞明白,我在ThinkPHP框架里也是使用命名空间完全没问题,怎么新建一个项目放连个文件,测试一下它死活都不行呢....连ZEND STUDIO编辑器都能显示出有存在Smarty_Test这个类,怎么运行的时候就是不行,,郁闷啊
------解决思路----------------------
很不错LLL
------解决思路----------------------
你没有加载含有 Smarty_Test 类定义的文件
------解决思路----------------------
是的,include包含进来
或者设置自动加载
spl_autoload_register();<br />use Smarty\Smarty_Test;<br /> <br />$smarty = new Smarty_Test();<br />$smarty->assign('name','Ned');<br />$smarty->debugging = true;<br />$smarty->display('index.tpl');
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template