Jump to content


Photo

PHP 4 Class error


  • Please log in to reply
5 replies to this topic

#1 b_angelr

b_angelr
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 17 October 2006 - 03:11 PM

I got some experienc now in php and was going to rebuild my website using oop, but know i recive an extrange parse error: here is the example code i used:
<?php
  class MySQL{
     //comment
     public $myvar = "mystring";
  }
?>

And now it says thet i have an unexpected T_STRING on line 4.

Somebody understands why these???

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 17 October 2006 - 03:46 PM

The visibility keywords (public, private, protected) are not available in php 4. Use var instead.

#3 b_angelr

b_angelr
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 17 October 2006 - 03:48 PM

darn.... fool me.... thnxs thorpe ;D

#4 b_angelr

b_angelr
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 18 October 2006 - 03:28 PM

Ok now i feel dumb... 3 years of php expirience for nothing.... i got an extrange warning... i declare a viriable as private, i use it in one function when i'm going to use it in a second function it is said that the veriable doesn't exists....
an example:
<?php
  class MySQL{
      private $foo;
      function first(){
        $foo = mysql_connect(blablabla);
      }

      function second(){
        mysql_close($foo); //here it sends me the error, it says $foo doesn't exist
      }
  }
?>
Please can someone help me

#5 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 18 October 2006 - 03:30 PM

<?php
  class MySQL{
      private $foo;
      function first(){
        $this->foo = mysql_connect(blablabla);
      }

      function second(){
        mysql_close($this->foo); //here it sends me the error, it says $foo doesn't exist
      }
  }
?>


#6 b_angelr

b_angelr
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 18 October 2006 - 03:39 PM

I wan to be like you when i grow up thorpe :D thanxs.....




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users