homepage Welcome to WebmasterWorld Guest from 54.211.100.183
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
quick parsing question
changing the strictness of the php parser
ryan_b83

5+ Year Member



 
Msg#: 3561078 posted 5:14 pm on Jan 29, 2008 (gmt 0)

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

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



 
Msg#: 3561078 posted 5:42 pm on Jan 29, 2008 (gmt 0)

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

jatar_k

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



 
Msg#: 3561078 posted 6:13 pm on Jan 29, 2008 (gmt 0)

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

5+ Year Member



 
Msg#: 3561078 posted 7:09 pm on Jan 29, 2008 (gmt 0)

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

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



 
Msg#: 3561078 posted 7:28 pm on Jan 29, 2008 (gmt 0)

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

5+ Year Member



 
Msg#: 3561078 posted 8:26 pm on Jan 29, 2008 (gmt 0)

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

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



 
Msg#: 3561078 posted 8:40 pm on Jan 29, 2008 (gmt 0)

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

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3561078 posted 8:53 pm on Jan 29, 2008 (gmt 0)

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved