NYCPHP Meetup

NYPHP.org

[nycphp-talk] A Cautionary Tale & then a question...

Brian Pang bpang at bpang.com
Fri Sep 5 11:24:51 EDT 2003


did this
$from = array( 'rgb' => '000000');
fix it for you?

which version of PHP on the old/new servers?

I would have to guess that since you didn't initialize $to and $from as
arrays, they didn't get echo'ed as such.

that's at least for the typing issue. I'm not sure why the other results
came up the way they did, even without declaring the arrays.

A good reason to always initialize arrays before populating them.
either.
If you were going to be adding more entries to the same array, I would use
$foo = array()
and array_push()
rather than using $foo = array('key' => 'value')
each time
Wouldn't the latter re-initialize the array and wipe out old values?




> I recently had to move one of my php sites from one server to another 
> and learned (once again) that not all php servers are the same (give me 
> a break, I've had a hangover for about three days now (or is it 
> four?)). One of the things that most attracted me to php after working 
> with asp for so long was its lenience towards doing things on-the-fly 
> without a lot of set up and declarations, etc. So I had some old code 
> that worked on my 1st server:
> 
> 	if ($_REQUEST['from']) {
> 		$from['rgb'] = $_REQUEST['from'];
> 	} else {
> 		$from['rgb'] = '000000';
> 	}
> 	if ($_REQUEST['to']) {
> 		$to['rgb'] = $_REQUEST['to'];
> 	} else {
> 		$to['rgb'] = 'FFFFFF';
> 	}
> 	
> 	echo "to: $to<BR>";
> 	echo "to[rgb]: {$to['rgb']}<BR>";
> 	
> 	echo "from: $from<BR>";
> 	echo "from[rgb]: {$from['rgb']}<BR>";
> 
> Which produced the output:
> 	to: Array
> 	to[rgb]: FFFFFF
> 	from: Array
> 	from[rgb]: 000000
> 
> When I moved the code to a new server, the results were:
> 	to: FFFFFF
> 	to[rgb]: F
> 	from: 4563456
> 	from[rgb]: 4
> 
> Of course, none of this was immediately obvious, since the code was 
> inside a php script that generated a png and had no echo statements. Of 
> course I should've originally said
> 
> 	$from = array( 'rgb' => '000000');
> 
> But I'm lazy.
> 
> I am a little curious about what setting in php.ini allows this 
> behavior on my (development) server though, since I suppose I should 
> turn it off so it matches with the outside world.
> 
> 
> 
> 
> 
> Jeff Knight
> jeff at lushmedia.com
> 212/213-6558 x 203
> LUSH media
> 110 W 40th St #1502
> New York, NY 10018
> 
> _______________________________________________
> talk mailing list
> talk at lists.nyphp.org
> http://lists.nyphp.org/mailman/listinfo/talk
> 
> 






More information about the talk mailing list