一個PHP命名空間的有關問題.很無語的有關問題.

來源:互聯網
上載者:User
一個PHP命名空間的問題....很無語的問題.....
直接上點小代碼



//用來定義一個繼承Smarty的子類,在建構函式中實現基本的路徑配置.....
namespace Smarty;

class Smarty_Test {
function setName(){
echo 'Name';
}
}



use Smarty\Smarty_Test;

$smarty = new Smarty_Test();
$smarty->assign('name','Ned');
$smarty->debugging = true;
$smarty->display('index.tpl');
?>


代碼如上,很簡單,兩段代碼的檔案結構在同一個目錄下

就這樣,運行死活說找不到類..........
Fatal error: Class 'Smarty\Smarty_Test' not found in ............
實在是沒搞明白,我在ThinkPHP架構裡也是使用命名空間完全沒問題,怎麼建立一個項目放連個檔案,測試一下它死活都不行呢....連ZEND STUDIO編輯器都能顯示出有存在Smarty_Test這個類,怎麼啟動並執行時候就是不行,,鬱悶啊
------解決思路----------------------
很不錯LLL
------解決思路----------------------
你沒有載入含有 Smarty_Test 類定義的檔案
------解決思路----------------------
是的,include包含進來
或者設定自動載入
spl_autoload_register();
use Smarty\Smarty_Test;

$smarty = new Smarty_Test();
$smarty->assign('name','Ned');
$smarty->debugging = true;
$smarty->display('index.tpl');

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.