I am learning OOP in PHP and am going through the tutorial in my "Beginning PHP5" book. I entered the following two files verbatim, but get the error message "Parse error: parse error, unexpected T_VARIABLE in /home/nanoserv/public_html/testdemo.php on line 5" class.Demo.php testdemo.php
i'm not an expert in OPP But i see a ";" missing . $objAnotherDemo = new Demo() $objAnotherDemo->name = "Ed"; PHP: $objAnotherDemo = new Demo() ;
I always do that - I always miss some mundane detail! Ok, semicolons fixed, now I get an error for the line that says: "Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/nanoserv/public_html/class.Demo.php on line 4" Thanks for your help!
are you sure you are running php5 ? because i think your problem is that the class is specifying variable and such as "public" or "protected". From what I've heard, PHP doesn't support public/private members of a class. Maybe it does in PHP5, but if you're running PHP4, that's your problem make a file , write in it : <?phpinfo();?> PHP: and see what php version you are using .
This is the case. I can't upgrade the version of PHP because my server owner prefers PHP4. (looks like I bought the wrong book!) What is the correct PHP4 syntax? Thanks!
I'm not sure how your host can prefer using an outdated version - for the most part, it's backwards compatible with PHP4 anyway. I recommend pushing your host a bit harder or moving to another. There's really not much point becoming familiar with the PHP4 OOP simply because your host is too lazy to upgrade. The object model in PHP5 is a significant improvement on PHP4 - it's not that there's a different syntax, it just doesn't support a whole lot of useful features of the newer version. In this instance, you can't specify public, private and protected members (or methods for that matter) and all are treated as public. For PHP4 and below, you need to use var $name.