Welcome to WebmasterWorld Guest from 54.145.39.186

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

quick parsing question

changing the strictness of the php parser

     

ryan_b83

5:14 pm on Jan 29, 2008 (gmt 0)

5+ Year Member



Hello, I am having trouble with a bunch of scripts that work fine on 1 server but not on another. I figured out the error was because I coded it so loosely. For example I would create array elements without declaring the variable as an array first. I know this is wrong to do it this way and I should have just declared all my arrays first but im just looking for a quick fix. Is there a way to lower the "strictness" of the php parser? I guess similar to the error_reporting() function, something for the setting the strictness?

Thanks,
Ryan

coopster

5:42 pm on Jan 29, 2008 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



In regards to ... what? Error reporting? The function you mentioned is where you can set the level of "strictness" for error handling.

jatar_k

6:13 pm on Jan 29, 2008 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



plus a non initialized variable will only throw a warning

are these warnings showing in the page?

as coop confirmed, just use
[php.net...]

unless there is something we are not understanding

ryan_b83

7:09 pm on Jan 29, 2008 (gmt 0)

5+ Year Member



Hi, yea well i know about the error_reporting() function which does hide the warning message. However the following code does not work:


<?
$error[] = "Some error here";
foreach($error as $k=>$v){
echo $v."<br>";
}
?>

This just echo's the letter "S" (the first letter in the error message), I think it is because although I am attempting to set it into an array, its setting it as a scalar variable because i didn't initiate the array. If it add


<?
$error = array();

continue code...

Then it works, because it sets the variable type as an array. Now I know that the correct thing to do would be to code stricter and actually instantiate my variables with the correct data types, but I have the whole thing working on 1 server (which allows this), and now that I am trying it on another server it wont set the variables the same. Any ideas?

Thanks,
Ryan

coopster

7:28 pm on Jan 29, 2008 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I think it is because although I am attempting to set it into an array, its setting it as a scalar variable because i didn't initiate the array.

No, that is not the case as PHP allows you to Create/modify with square-bracket syntax [php.net]. If the array does not yet exist it will be created.

Which version of PHP is running on the server that is not working correctly?

ryan_b83

8:26 pm on Jan 29, 2008 (gmt 0)

5+ Year Member



Hum, ok could the fact that register_globals is turned on?

I know that the server that it works on, the register_globals is off... im not sure if thats the only difference.

Thanks,
Ryan

coopster

8:40 pm on Jan 29, 2008 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Which version of PHP? PHP 4.7? PHP 5.2.5?

I don't believe register_globals would have anything to do with it. To find out, you could always dump the variable prior to using it here to see if it exists in memory already. You'll get an error if it doesn't exist.

<?php 
print '<pre>'; [b]var_dump [php.net]($error); print '</pre>';
$error[] = "Some error here";
foreach($error as $k=>$v){
echo $v."<br>";
}
?>

Have you viewed the source in the browser too and make sure that not just the "S" is being written? Perhaps the text is indeed there, just not rendering in the browser.

cameraman

8:53 pm on Jan 29, 2008 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



I know that you can get into trouble with this:

$error = "hello";
$error[] = "Some error";

The fix is to either
unset($error);
or
$error = array();
before reusing it as an array.

I ran across this a couple of months ago, and verified that it caused problems on both my shared hosting 4.7 LAMP and my 5.2.something WAMP home game.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month