jefrat72 Posted July 20, 2006 Share Posted July 20, 2006 I'm trying to learn PHP out of a book, the machine I started on had PHP 5, the server I'm on now has PHP 4.3.3. So when I run my code I get this error:"Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/allsys5/public_html/page.php on line 4"I [b]can not[/b] go back to PHP 5, so can anyone help me work out the error in this following code? <?phpclass Page{public $content;public $title = 'Bob's Book Store';public $keywords = 'Bob's Book Store, Three Letter Abbreviation, some of my best friends are search engines';public $buttons = array ( 'Home' => 'index.php', 'Books' => 'Books.php', 'Helpful Links' => 'helpfullinks.php', 'Contact Me' => 'feedback.html', );// class Page's operationspublic function _set($name, $value) { $this->$name = $value; }public function Display() { echo "<html>\n<head>\n"; $this -> DisplayTitle(); $this -> DisplayKeywords(); $this -> DisplayStyles(); echo "</head>\n<body bgcolor='white'>\n"; $this -> DisplayHeader(); $this -> DisplayMenu ($this->buttons); echo $this->content; $this -> DisplayFooter(); echo "</body>\n</html>\n"; }public function DisplayTitle() { echo "<title> ".$this->title." </title>"; }public function DisplayKeywords() { echo "<meta name=\"keywords\" content=\"".htmlentities($this->keywords)."\" />"; }public function DisplayStyles() {?><style><!-- h1 {color:white; font-size:34pt; text-align:center; font-family:TSCu_Comic,arial,sans-serif} .menu {color:white; font-size:16pt; text-align:center; font-family:TSCu_Comic,arial,sans-serif; font-weight:bold} p {color:steelblue; font-size:12pt; text-align:justify; font-family:arial,sans-serif} p.foot {color:black; font-size:15pt; text-align:center; font-family:TSCu_Comic,arial,sans-serif; font-weight:bold} a:link,a:visited,a:active {color:red; font-size:16pt} a:hover {color:green}--></style><?php }public function DisplayHeader() {?> <table width="100%" cellpadding="1" cellspacing="0"> <TR> <TD bgcolor="steelblue"> <h1>Bob's <br> Book Store </br></h1> </TD> </TR> </table><?php }public function DisplayMenu($buttons) { echo "<table width='100%' bgcolor='steelblue' cellpadding='6' cellspacing='4'>\n"; echo " <tr>\n"; // calculate button size $width = 100/count($buttons); foreach ($buttons as $name=>$url) { $this -> DisplayButton($width, $name, $url, !$this->IsURLCurrentPage($url)); } echo " </tr>\n"; echo "</table>\n"; }public function IsURLCurrentPage($url) { if(strpos($_SERVER['PHP_SELF'], $url )==false) { return false; } else { return true; } }public function DisplayButton($width, $name, $url, $active = true) { if ($active) { echo "<td width='".htmlentities($width)."%'> <a href ='".htmlentities($url)."'> <img src='reddot.gif' alt ='".htmlentities($name)."' border ='0' /></a> <a href='".htmlentities($url)."'><span class='menu'>$name</span></a></td>"; } else { echo "<td width='".htmlentities($width)."%'> <img src='GREENDOT.GIF'> <span class='menu'>$name</span></td>"; } }public function DisplayFooter() {?> <table width="100%" bgcolor="white" cellpadding="2" border="0"> <TR> <p class="foot">Please call me at (123) 555-1234 <br /> or email at <a href="feedback.html">test@anywhere.com</a></p> </TR> </table><?php }}?> Quote Link to comment https://forums.phpfreaks.com/topic/15137-getting-parse-error-on-php-433/ Share on other sites More sharing options...
ChaosXero Posted July 20, 2006 Share Posted July 20, 2006 public $title = 'Bob's Book Store'; is line 4 and I notice you have Bob's should be bob\'s. I think that is where the error is. Quote Link to comment https://forums.phpfreaks.com/topic/15137-getting-parse-error-on-php-433/#findComment-61006 Share on other sites More sharing options...
wildteen88 Posted July 20, 2006 Share Posted July 20, 2006 The main reason is becuase PHP4 doesnt have the same level of OOP as PHP5 has. For example PHP doesnt support public, private or protected keywords when defining methods/objects with PHP4.I'd recommend you to read the manual for using OOP with PHP4, [url=http://uk.php.net/manual/en/language.oop.php]here[/url].Also if you are learning. I would strongly suggest you install Apache2.0.x, PHP5.x and MySQL4.x on your local PC/Mac/Laptop. This will allow you to develope and test your PHP scripts locally, offline, rather than using a host. Quote Link to comment https://forums.phpfreaks.com/topic/15137-getting-parse-error-on-php-433/#findComment-61089 Share on other sites More sharing options...
jefrat72 Posted July 20, 2006 Author Share Posted July 20, 2006 [quote author=wildteen88 link=topic=101236.msg400516#msg400516 date=1153410732]Also if you are learning. I would strongly suggest you install Apache2.0.x, PHP5.x and MySQL4.x on your local PC/Mac/Laptop. This will allow you to develope and test your PHP scripts locally, offline, rather than using a host.[/quote]That's where I ran into the problem. I wrote this on a PCBSD machine with Apache2.0.x, PHP5.x and MySQL5.x and transferred the code to a host using 4.3.3. My mistake but now gotta fix it. Thanks for the link. Quote Link to comment https://forums.phpfreaks.com/topic/15137-getting-parse-error-on-php-433/#findComment-61116 Share on other sites More sharing options...
jefrat72 Posted July 20, 2006 Author Share Posted July 20, 2006 [quote author=wildteen88 link=topic=101236.msg400516#msg400516 date=1153410732]I'd recommend you to read the manual for using OOP with PHP4, [url=http://uk.php.net/manual/en/language.oop.php]here[/url].[/quote]Just so I'm heading in the right direction it looks like serialize() unserialize() is to PHP4 as Public is to PHP5? In other words that's what I need to be using to get this code to work correctly? Quote Link to comment https://forums.phpfreaks.com/topic/15137-getting-parse-error-on-php-433/#findComment-61223 Share on other sites More sharing options...
wildteen88 Posted July 20, 2006 Share Posted July 20, 2006 No I dont think so. serialize and unserialize only works on strings. It cannot be used when defining a function/variable within a class. For example cannot do this:[code]serialize function _set($name, $value) { $this->$name = $value; }[/code]The only way to get your code to work is delete any instances of public, private or protected before a function/varible. Then your code should work. Quote Link to comment https://forums.phpfreaks.com/topic/15137-getting-parse-error-on-php-433/#findComment-61230 Share on other sites More sharing options...
jefrat72 Posted July 20, 2006 Author Share Posted July 20, 2006 I did get rid of the "Public" and it worked just fine in Firefox and Opera, IE is grumpy about it but I'll figure it out.Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/15137-getting-parse-error-on-php-433/#findComment-61317 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.