Class Object in print_r php 4x vs 5x

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Class Object in print_r php 4x vs 5x

Post by hawleyjr »

This is probably one of those changes that nobody has noticed or if they did just shrugged it off because as far as I can tell it doesn't really affect anything. Nonetheless it really stumped me when I was trying to debug a class.

Using the following code:

Code: Select all

echo 'Current PHP version: ' . PHP_VERSION;

class Foo{
	var $myFoo;
	function Foo(){
		
	}
	function bar(){
		
	}	
}

$foo = new Foo();

echo '<pre>'; print_r($foo); echo '</pre>';
Check out the capitalization of the class name in PHP 4x vs 5x . I know this is small beans however (As far as I can tell it doesn't matter), it baffled me during the debug....

Code: Select all

Current PHP version: 4.3.2

foo Object
(
    [myFoo] => 
)

Code: Select all

Current PHP version: 5.1.1

Foo Object
(
    [myFoo] => 
)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

5 returns class names, method names and function names all case sensitive (in the exact case they were declared as).
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

I just read that the other day and haven't even used PHP5 yet...so that wouldn't stump me :)

But I can see how it might throw you off slightly...

As far as having implications? Yes it could...I often play around with class names in code I write. Until I read that I never bothered to convert to common case, however since reading that article, I started doing so, so my code acts accordingly on PHP when I eventually port it over to version 5.0 :)

What baffled me, was PHP returning class names as lower case...actually caused me a headache....cuz in that instance I needed exact case :(

Ah well...PHP ain't perfect, but neither am I (although I am close) so I guess i'll forgive it :P

Cheers :)
Post Reply