請問 PHP 新手問題

config.php
<?
define('SITENAME','ABC')



index.php
<? require_once('config.php');
echo SITENAME;

請問為何唔俾出 SITENAME??

Warning: Use of undefined constant SITENAME - assumed 'SITENAME' (this will throw an Error in a future version of PHP)

1.
define('SITENAME','ABC')
呢句漏左分號

2. 請睇下define呢句return乜俾你先, true係成功, false係失敗

TOP

回覆 2# KinChungE


    sorry 我e 道打漏左

其實我只想將  config.php 入面 define o既 SITENAME
帶去index.php 用
但係唔俾

TOP

回覆  KinChungE


    sorry 我e 道打漏左

其實我只想將  config.php 入面 define o既 SITENAME
帶去in ...
calvinlai 發表於 2022-3-24 14:14


咁第二條問題呢, true定false?

TOP

本帖最後由 calvinlai 於 2022-3-24 14:23 編輯

回覆 4# KinChungE

return SITENAME;

係就出句
    Warning: Use of undefined constant SITENAME - assumed 'SITENAME' (this will throw an Error in a future version of PHP)

其實 define const 係唔係唔可以當 global 咁帶去另一版 php 咁用 ?

TOP

config.php
<?
$result = define('SITENAME','ABC');
echo $result;


如果出false既話你乜都唔使做, 成句define失敗左 (有機會同其他地方global variable等撞名)

TOP

回覆 6# KinChungE





    明白了!  謝謝  ching 解說!

TOP

應該係require_once的關係,轉用include或require應該可以。

TOP