Page 1 of 1

Class Object in print_r php 4x vs 5x

Posted: Fri Mar 31, 2006 3:09 pm
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] => 
)

Posted: Fri Mar 31, 2006 3:25 pm
by feyd
5 returns class names, method names and function names all case sensitive (in the exact case they were declared as).

Posted: Fri Mar 31, 2006 4:03 pm
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 :)