Folks,
Why this shows undefined Variable since it is Super Global Variable ? It should always be filled with something, even blank. And not show error it in undefined.
[code]
<?php
foreach($php_errormssg as $error)
{
if(is_scalar($php_errormssg))
{
echo ‘Scalar Variable:’ .$global; echo ‘<br>’;
}
else
{
echo ‘Non-Scalar Variable:’ .print_r($global); echo ‘<br>’; //Shows error as Variable not Scalar Variable. So, don’t echo but print_r instead.
}
}
?>
**Notice: Undefined variable: php_errormssg in C:xampphtdocsTemplatestest.php on line 3
If the Global Variable $php_errormsg is empty then it should just show blank.
How to fix this ?
2nd Code
Look this following one works fine:
[code]
<?php
foreach($GLOBALS as $global)
{
if(is_scalar($GLOBALS))
{
echo ‘Scalar Variable:’ .$global; echo ‘<br>’;
}
else
{
echo ‘Non-Scalar Variable:’ .print_r($global); echo ‘<br>’; //Shows error as Variable not Scalar Variable. So, don’t echo but print_r instead.
}
}
?>
I get echoed …
**Array ( ) Non-Scalar Variable:1
Array ( ) Non-Scalar Variable:1
Array ( [PHPSESSID] => tsdktj0t5umjptqdbgi73fnje0 ) Non-Scalar Variable:1
Array ( ) Non-Scalar Variable:1
Array ( [_GET] => Array ( ) [_COOKIE] => Array ( [PHPSESSID] => tsdktj0t5umjptqdbgi73fnje0 ) [*RECURSION*RECURSION
Array ( [_GET] => Array ( ) [_COOKIE] => Array ( [PHPSESSID] => tsdktj0t5umjptqdbgi73fnje0 ) [*RECURSION*RECURSION
Is anything wrong with my 2nd code too ? Yes or no ?
And this 3rd code work fine too:
[code]
<?php
foreach($_SERVER as $serve)
{
echo $serve; echo ‘<br>’; //Shows error as Variable not Scalar Variable. So, don’t echo but print_r instead.
}
if(is_scalar($_SERVER))
{
echo ‘Is Scalar Variable.’;
}
else
{
echo ‘Is NOT Scalar Variable!’;
}
?>
Tell me. Is anything wrong with this 3rd code too ?
If not then why 1st one fails ?