__construct

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thiscatis
Forum Contributor
Posts: 434
Joined: Thu Jul 20, 2006 11:00 am

__construct

Post by thiscatis »

Hello, i`m doing some tutorials on OOP in php5 and a simple script like:

Code: Select all

<?php 

class TextBox {

	var $body_text = "my text";
	
	
	function __construct($text_in) {					
			$this->body_text = $text_in; 
                                              }	
	function display() {	
			echo "<table border=1><tr><td>$this->body_text</td></tr></table>";			
						}
						
}
$box = new TextBox("Hello");
$box->display();	
?>
will still display "my text" instead of "hello"
I first thought it was still parsed trough php4, so I contacted my hosting helpdesk and told me to add a line to my htaccess file.
the htaccess file now looks like

Code: Select all

RewriteEngine on
RewriteRule ^([A-Za-z]+)$ /$1/ [R]
RewriteRule ^([A-Za-z]+)/$ /index.php?module=$1
AddType x-mapp-php5 .php4
but it still displays the "my text" instead of "hello".
Is there something wrong with the script or the htaccess config or something else?

Thanks!
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Are you definitely running PHP5? Does this give you parse errors?

Code: Select all

class TextBox { 

        public $body_text = "my text"; 
        
        
        public function __construct($text_in) {                                        
                        $this->body_text = $text_in; 
                                              }  
        public function display() {    
                        echo "<table border=1><tr><td>$this->body_text</td></tr></table>";                  
                                                } 
                                                
} 
$box = new TextBox("Hello"); 
$box->display();
thiscatis
Forum Contributor
Posts: 434
Joined: Thu Jul 20, 2006 11:00 am

Post by thiscatis »

Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}

But I think my .htaccess file is correct because the rewrite rule still works.
So it doesn`t override the default php4

anything you see suspicious in the htaccess file?
thiscatis
Forum Contributor
Posts: 434
Joined: Thu Jul 20, 2006 11:00 am

Post by thiscatis »

maybe it should be
AddType x-mapp-php5 .php

instead of
AddType x-mapp-php5 .php4
thiscatis
Forum Contributor
Posts: 434
Joined: Thu Jul 20, 2006 11:00 am

Post by thiscatis »

YES.
works,

I love being so frustrated about a problem that you keep looking and reviewing every step until you found a solution.
Can finaly start with the next chapter in my book I just bought.
I`m as excited as bill gates when he looked trough his window and had an "aha"-moment
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

thiscatis wrote:I`m as excited as bill gates when he looked trough his window and had an "aha"-moment
:lol:
Post Reply