Page 1 of 1

__construct

Posted: Mon Feb 19, 2007 4:19 pm
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!

Posted: Mon Feb 19, 2007 4:21 pm
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();

Posted: Mon Feb 19, 2007 4:27 pm
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?

Posted: Mon Feb 19, 2007 4:31 pm
by thiscatis
maybe it should be
AddType x-mapp-php5 .php

instead of
AddType x-mapp-php5 .php4

Posted: Mon Feb 19, 2007 4:33 pm
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

Posted: Mon Feb 19, 2007 4:37 pm
by Chris Corbyn
thiscatis wrote:I`m as excited as bill gates when he looked trough his window and had an "aha"-moment
:lol: