Page 1 of 1
code not working in php 5
Posted: Mon Jan 15, 2007 9:34 am
by pedroz
It used to work on php 4 but not on php 5.2
Code: Select all
$forums = ($action == 'forums' && $batch == 'index');
if (!$forums){
echo "yes;"
}else{
echo "no";
}
Any idea to adapt it to php 5.2?
I know I can use the code below but I have several code and I do not want to change it...
Code: Select all
if (!($action == 'forums' && $batch == 'index')){
echo "yes;"
}else{
echo "no";
}
Thanks
Posted: Mon Jan 15, 2007 9:55 am
by feyd
Where does $action and $batch come from?
Posted: Mon Jan 15, 2007 10:41 am
by John Cartwright
My guess is your version of php4 had register globals enabled, and your php5 version does not (this is a good thing). Run the following in a new file and tell us the results please.
Code: Select all
<?php
$neg = array('off', 0, false, '', null);
$flags = array(
'Register Globals' => 'register_globals',
'Short Tags' => 'short_open_tag',
'Display Errors' => 'display_errors',
'Magic Quotes GPC' => 'magic_quotes_gpc',
'Magic Quotes Runtime' => 'magic_quotes_runtime',
'Magic Quotes Sybase' => 'magic_quotes_sybase',
);
$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
foreach ($flags as $n => $v)
{
$flags[$n] = (in_array(strtolower(ini_get($v)), $neg) ? 'Off' : 'On');
}
$cli = (php_sapi_name() == 'cli');
$eol = "\n";
$gle = get_loaded_extensions();
$rows = array();
$le = '';
$wide = 4;
$j = count($gle);
$pad = $wide - $j % $wide;
$len = max(array_map('strlen', $gle));
$func = create_function('$a', 'return str_pad($a, ' . intval($len) . ');');
$gle = array_map($func, $gle);
for($i = 0; $i < $j; $i += $wide)
{
$le .= ' ' . implode(' ', array_slice($gle, $i, $wide)) . $eol;
}
$ec = array(
'E_STRICT' => 2048, 'E_ALL' => 2047, 'E_USER_NOTICE' => 1024,
'E_USER_WARNING' => 512, 'E_USER_ERROR' => 256, 'E_COMPILE_WARNING' => 128,
'E_COMPILE_ERROR' => 64, 'E_CORE_WARNING' => 32, 'E_CORE_ERROR' => 16,
'E_NOTICE' => 8, 'E_PARSE' => 4, 'E_WARNING' => 2, 'E_ERROR' => 1,
);
$e = array();
$t = $er;
foreach ($ec as $n => $v)
{
if (($t & $v) == $v)
{
$e[] = $n;
$t ^= $v;
}
}
if (ceil(count($ec) / 2) + 1 < count($e))
{
$e2 = array();
foreach ($ec as $n => $v)
{
if (!in_array($n, $e) and $n != 'E_ALL')
{
$e2[] = $n;
}
}
$er = $er . ' ((E_ALL | E_STRICT) ^ ' . implode(' ^ ', $e2) . '))';
}
else
{
$er = $er . ' (' . implode(' | ', $e) . ')';
}
if (!$cli)
{
echo '<html><head><title>quick info</title></head><body><pre>', $eol;
}
echo 'PHP Version: ', $ve, $eol;
echo 'PHP OS: ', $os, $eol;
echo 'Error Reporting: ', $er, $eol;
foreach ($flags as $n => $v)
{
echo $n, ': ', $v, $eol;
}
echo 'Loaded Extensions:', $eol, $le, $eol;
if (!$cli)
{
echo '</pre></body></html>', $eol;
}
?>
Posted: Mon Jan 15, 2007 10:43 am
by pedroz
Thanks.
I found the problem... It was a question of short tags "<?" not allowed on php5
Posted: Mon Jan 15, 2007 12:48 pm
by aaronhall
Allowed if enabled in PHP5; presumably not on your server

Posted: Mon Jan 15, 2007 12:53 pm
by feyd
aaronhall wrote:Allowed if enabled in PHP5; presumably not on your server

Don't encourage people to use short tags.

Posted: Mon Jan 15, 2007 1:08 pm
by pedroz
No... I changed all <? to <?php
The problem was that the script was stopping in the line of the code I posted...
It sounded strange but then I remembered it could be the short tags
DO NOT use short tags
Posted: Wed Jan 17, 2007 12:47 am
by aaronhall
feyd wrote:aaronhall wrote:Allowed if enabled in PHP5; presumably not on your server

Don't encourage people to use short tags.

Alright, short tags were taken out of PHP5... they no longer exist... don't even check
They are being considered for removal in PHP6 if I remember correctly -- right?
Posted: Wed Jan 17, 2007 8:39 am
by feyd
aaronhall wrote:They are being considered for removal in PHP6 if I remember correctly -- right?
Last I saw it wasn't even a consideration; they were already gone along with register_globals and asp tags.