PHP function parameters question

xappie

[H]ard|Gawd
Joined
Dec 13, 2000
Messages
1,378
Hi all

PHP Noob here.

Does anyone know what differences could exist between a live webserver and my production environment to cause a function to work online, but fail locally?

I have taken over a project and one of the functions that is used on every page is defined thusly:

Code:
public function getFooter($extras){
//etc
}

Wherever the function is called, it is called like this:

Code:
<?php echo $header->getFooter(); ?>

Now, when I run this locally, I get the expected PHP error that the method is missing an input parameter. However, this same code seems to run fine online. Any ideas why? Could it be a difference in PHP version? OS version? Something like "on error resume next" turned on for the webserver? I don't get it.

I can fix this easily by putting an empty string '' into the method calls, but I hesitate to change something that appears to be working online.
Any advice is appreciated.
 
If you post the rest of the function, we can tell you more. This is a behavior difference, and thus likely to be a version difference. A potential fix, which you will want to test completely before implementing it, is to rewrite the function stub as such:

Code:
public function getFooter($extras = ""){
//etc
}

This gives $extras a default value of "", if none other is specified. But again, without knowing the full function, it's just a guess.
 
That seems like a good solution.

Here is the jist of the funtction. I didn't write this, but it looks like it basically returns some html with the value of $extras appended if it was not empty.

Code:
public function getFooter($extras){
	if (strlen($extras) > 0){
		$extras = '
			<tr><td class="content" colspan="3" align="center" style="white-space: nowrap;">'.$extras.'</td></tr>';
		}

		$datemod = $this->_lastmodified;
		$str =<<<HERE
				//misc HTML HERE
					$extras

			HERE;
		return $str;
	}
 
It is most likely a version difference like stated above, or some other default setting was changed to make it less secure/picky about functions, variables, etc.

But yeah, try the suggestion he made. If it doesn't work right, then make a php file on both servers that just has:

Code:
<?php

phpinfo();

?>

Run that page, and it will give lots of information about which version of php it is, and what the php.ini settings are.
 
It is most likely a version difference like stated above, or some other default setting was changed to make it less secure/picky about functions, variables, etc.

But yeah, try the suggestion he made. If it doesn't work right, then make a php file on both servers that just has:

Code:
<?php

phpinfo();

?>

Run that page, and it will give lots of information about which version of php it is, and what the php.ini settings are.

Ok, got it.
There are MAJOR differences. Notably, the "Configure Command" section, and the "Server API" section. I am running in "apache 2.0 handler" and the live site is using CGI. Now I have to figure out how to make my local copy run in CGI API as well, if that is possible.
 
Ok, got it.
There are MAJOR differences. Notably, the "Configure Command" section, and the "Server API" section. I am running in "apache 2.0 handler" and the live site is using CGI. Now I have to figure out how to make my local copy run in CGI API as well, if that is possible.

How its running shouldn't make a huge difference, but rather what version and what settings are in the php.ini file.
 
Hmm yeah my local copy is PHP version 5.2.1 and the online one is 5.2.3.

I am running this through VS.PHP locally, so I am not sure how to upgrade PHP versions.
 
You probably have display_errors turned on in php.ini in your local environment and off on the production box, or your error_level setting is different. This is pretty normal, and has nothing to do with versions (5.2.1 and 5.2.3 are very close). If you want to see the same behavior make sure those two php.ini settings are identical.
 
Just make the modification I suggested, and you should be good. Anything built off that function will still work as it's supposed to.
 
You probably have display_errors turned on in php.ini in your local environment and off on the production box, or your error_level setting is different. This is pretty normal, and has nothing to do with versions (5.2.1 and 5.2.3 are very close). If you want to see the same behavior make sure those two php.ini settings are identical.

Exactly. If the guy setting up the production server is worth his salt he has display errors turned off and is probably ignoring notices/warnings and only logging errors.

Add this command here at the top set to display all errors and you should see what you're looking for.
http://us.php.net/error_reporting
 
Well I think I figured out most of my problems.

They stem from two basic problems, as far as I can tell:

1) This site was developed for a UNIX environment and has lots of directory/path functions that split strings on separators like "/", that are "\" in WINDOWS. ie: "/u/o/whatever" vs "c:\u\o\whatever" .

2) Whoever coded this thing was a monkey. The site is FULL of errors if you turn on the error display. FULL. Monkey.
 
From my little knowledge of PHP and files. the engine should work out the differences between the the two operating systems unless you specify the absolute path i.e. /home/user/folder.
 
From my little knowledge of PHP and files. the engine should work out the differences between the the two operating systems unless you specify the absolute path i.e. /home/user/folder.

And that is EXACTLY what seems to be done throughout this code. It's crazy.
 
Back
Top