开发者

undefined constant problem with xampp

开发者 https://www.devze.com 2023-04-03 06:17 出处:网络
i have two problems with xamp first problem My code if($_REQUEST[\'foo\']){ echo \'bar\'; } error: Notice: Undefined index: foo in C:\\xampp\\ht开发者_JAVA百科docs\\test_file.php on line 5

i have two problems with xamp

first problem

My code

if($_REQUEST['foo']){
    echo 'bar';
}

error: Notice: Undefined index: foo in C:\xampp\ht开发者_JAVA百科docs\test_file.php on line 5

second problem

My code

define( THEME ,'theme/');

Error: Notice: Use of undefined constant THEME - assumed 'THEME'

How i can solve this problems ?

problem solved: i was think the problem is in xampp because files was working fine on apache but sorry that's was my maistake , thank you all


if (key_exists('foo', $_REQUEST) && $_REQUEST['foo']){
...
}

Access to array keys that don't exist emit a notice (except for special constructs like isset or empty; incidentally, you could rewrite your condition as if (!empty($_REQUEST['foo'])), since empty is aligned with whether a value would be converted to FALSE if coerced to a boolean), so you should check for them first.

define( "THEME" ,'theme/');

define takes a string as a first parameter, just THEME looks like a constant, so PHP looks for one; not finding one it reverts to the string "THEME", which is what you want. But it's a string you want, you should give it in the first place.


First:

if (!empty($_REQUEST['foo'])){
    echo 'bar';
}

Second:

define('THEME', 'theme/');


please, read this about using $_REQUEST: http://devlog.info/2010/02/04/why-php-request-array-is-dangerous/

$_REQUEST contains everything from $_POST, $_GET and $_COOKIE. If there is nog $_POST['foo'], $_GET['foo'] or $_COOKIE['foo'], then $_REQUEST['foo'] don't exists.

Second:

if you want to define something, always use "" or '', like for example:

define( "THEME" , "/theme/goes/here/" );
0

精彩评论

暂无评论...
验证码 换一张
取 消