Expecting T_FUNCTION ?

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
DoubleUB
Forum Newbie
Posts: 2
Joined: Wed Aug 12, 2009 7:58 am

Expecting T_FUNCTION ?

Post by DoubleUB »

Hi,

i have this wierd problem, this is my code:

Code: Select all

<?php 
 
abstract class UserPrefs 
{ 
   $tablename = ''; 
    
   abstract function form_details(&$data, $uid, $method); 
   abstract function handle_form(&$data, $uid, $method); 
    
   function get_table_data($uid) 
   { 
      DBase::query("SELECT * FROM {$this->tablename} WHERE user_id = {$uid}"); 
      if (($data = DBase::fetch_result()) === FALSE) $data = array(); 
      return $data; 
   } 
    
   function get_post_data() 
   { 
      $data = array(); 
      foreach ($_POST as $key => $val) 
         if (preg_match("/^({$this->tablename}_)(.*)/", $key, $matches)) $data[$matches[2]] = $val; 
      return $data; 
   } 
} 
 
?>
And when i try to run this, PHP gives me this error:
Parse error: parse error, expecting `T_FUNCTION' in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\cms\userprefs.php on line 5

So what? I can only declare functions inside an abstract class? Also, when i write a class extending this one, and I put '$tablename = 'anything';' in it, PHP also gives me this error. Anyone got any clue what I'm doing wrong here?
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Expecting T_FUNCTION ?

Post by Mark Baker »

public, private, protected?
DoubleUB
Forum Newbie
Posts: 2
Joined: Wed Aug 12, 2009 7:58 am

Re: Expecting T_FUNCTION ?

Post by DoubleUB »

Ah, that works. Not really used to using visibility keywords in PHP.
Post Reply