Go Back   Webmaster Malaysia Forum » Website Design & Development » Website Programming

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 14-04-2004, 11:18 AM
nurulmajdi's Avatar
Inspired Webmaster
 
Join Date: Feb 2004
Location: Klang Bandar Diraja
Posts: 160
Rep Power: 62
nurulmajdi is on a distinguished road
Send a message via Yahoo to nurulmajdi
Class

aku try nak apply OOP dlm previous php projek aku... so, skang nih tgh meng'apply' la... aku just tiru je dlm buku.. tp kuar parse error... dah tiru sebijik sebijan dah... okeh aku paste kan aku punya code kat sini....

-------------------------------user.php----------------------------------------

<?php
//define class for tracking users
class User
{
//properties
public $name;
private $password, $lastLogin;

//methods
public function __construct($name, $password)
{
$this->name = $name;
$this->password = $password;
$this->lastLogin = time();
$this->accessess++;

}

function getlastLogin()
{
return (date("M d Y",$this->lastLogin));
}

}
//create an instance
$user = new User("Leon","sdf123");
//get the last login date
print($user->getlastLogin()."<br>\n");
//print the user's name
print ("$user->name<br>\n");

?>

--------------------------------Ouput---------------------------------------

Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in c:\phpdev\www\try oop\user.php on line 6
__________________
To follow the path:
Look to the master,
Follow the master,
Walk with the master,
See through the master,
Become the master.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 14-04-2004, 12:06 PM
nurulmajdi's Avatar
Inspired Webmaster
 
Join Date: Feb 2004
Location: Klang Bandar Diraja
Posts: 160
Rep Power: 62
nurulmajdi is on a distinguished road
Send a message via Yahoo to nurulmajdi
i put away 'public' and 'private' and it works as i want.. but can anyone tell me what exactly happen?
__________________
To follow the path:
Look to the master,
Follow the master,
Walk with the master,
See through the master,
Become the master.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 14-04-2004, 12:51 PM
lcf's Avatar
lcf lcf is offline
Pro-Blogger
 
Join Date: Feb 2003
Location: Kluang, Johor
Posts: 2,376
Rep Power: 118
lcf will become famous soon enough
Send a message via ICQ to lcf Send a message via MSN to lcf Send a message via Yahoo to lcf
I am not sure where you copy the code. As far as I know, there are other ways to initial private, public and protected variable.
Quote:
All private variables and functions always start with underscore "_" followed by lowercase letters like var $_myvar;

All Protected variables and functions always start with "_T" followed by lowercase letters like var $_Tmyvar;

All Public variables and functions do not start with underscore "_" like var $myvar;

All variables and functions always start with lowercase letter (no uppercase) like var $_myvar; and NOT like var $_Myvar;

PHP Code:
class someabc {
        var 
$_conn;                     // Private variable
        
var $_Tmyvar;                   // Protected variable
        
var $connMYCONNECTION;          // Public variable
        
var $connToDb;                  // Public variable
        
var $myvar3;                    // Public variable
        
var $myvarTHISTEST;             // Public variable

        
function _foofunction() {}      // Private function
        
function _Tfoofunction() {}     // Protected function
        
function foofunction() {}       // Public function

Source: http://www.linuxdocs.org/HOWTOs/PHP-HOWTO-7.html

This explain why the script works after your removed "private", "public". Please note that, all variables in your script have become PUBLIC type.
__________________
LiewCF | Malaysia Bloggers Forum
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 14-04-2004, 02:05 PM
zaimlah's Avatar
Inspired Webmaster
 
Join Date: Jul 2001
Location: ttdi
Posts: 129
Rep Power: 92
zaimlah is on a distinguished road
actually php4 langsung tak ada support utk public, private or protected access. semua members dan methods automatically jadi public, no matter what.

tapi dalam php5, OOP features dia lagi lengkap, so public/private/protected access dah di-implement-kan, syntax dia exactly mcm yg pasted:
PHP Code:
public $name;
private 
$password$lastLogin;
...
public function 
__construct($name$password)
{ ... } 
so that example must be a php5 example...

btw: php5 release candidate 1 is out!
__________________
blog:zaim_bakar_blog | biz:box
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 14-04-2004, 02:13 PM
lcf's Avatar
lcf lcf is offline
Pro-Blogger
 
Join Date: Feb 2003
Location: Kluang, Johor
Posts: 2,376
Rep Power: 118
lcf will become famous soon enough
Send a message via ICQ to lcf Send a message via MSN to lcf Send a message via Yahoo to lcf
ya, zaimlah is right. So, nurulmajdi stick with the example I given or upgrade to PHP5.
__________________
LiewCF | Malaysia Bloggers Forum
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 14-04-2004, 02:55 PM
nurulmajdi's Avatar
Inspired Webmaster
 
Join Date: Feb 2004
Location: Klang Bandar Diraja
Posts: 160
Rep Power: 62
nurulmajdi is on a distinguished road
Send a message via Yahoo to nurulmajdi
hmm.... i got this from a book which fully revised for php 5. I want to upgrade since i know php 5 RC is released, but i'm using phpdev 423 and it using php 4.2.3 and i don't know which file to altered.
__________________
To follow the path:
Look to the master,
Follow the master,
Walk with the master,
See through the master,
Become the master.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 14-04-2004, 04:33 PM
lcf's Avatar
lcf lcf is offline
Pro-Blogger
 
Join Date: Feb 2003
Location: Kluang, Johor
Posts: 2,376
Rep Power: 118
lcf will become famous soon enough
Send a message via ICQ to lcf Send a message via MSN to lcf Send a message via Yahoo to lcf
if you use phpdev 423(php 4.2.3) then you cannot use the PHP5 coding. you may either upgrade your PHP version or stick with 4.2.3(do not use the private, public, protected).
__________________
LiewCF | Malaysia Bloggers Forum
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 14-04-2004, 05:19 PM
nurulmajdi's Avatar
Inspired Webmaster
 
Join Date: Feb 2004
Location: Klang Bandar Diraja
Posts: 160
Rep Power: 62
nurulmajdi is on a distinguished road
Send a message via Yahoo to nurulmajdi
okeh lcf.. bertindak mengikut arahan!
__________________
To follow the path:
Look to the master,
Follow the master,
Walk with the master,
See through the master,
Become the master.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 14-04-2004, 11:19 PM
hymns's Avatar
Senior Webmaster
 
Join Date: Nov 2001
Location: Johor
Posts: 769
Rep Power: 101
hymns is on a distinguished road
Send a message via ICQ to hymns Send a message via Yahoo to hymns
heh upgrade lah...
clean install satu per satu...
__________________
I hate when:

vBulletin Message:
Sorry! The administrator has specified that users can only post one message every 60 seconds
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 14-04-2004, 11:36 PM
lcf's Avatar
lcf lcf is offline
Pro-Blogger
 
Join Date: Feb 2003
Location: Kluang, Johor
Posts: 2,376
Rep Power: 118
lcf will become famous soon enough
Send a message via ICQ to lcf Send a message via MSN to lcf Send a message via Yahoo to lcf
if you code in PHP5 but your webser use PHP4 then headache lah~
Since PHP5 is not final release yet, it is advice not to use it for development purposes.
__________________
LiewCF | Malaysia Bloggers Forum
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #11 (permalink)  
Old 15-04-2004, 12:03 AM
hymns's Avatar
Senior Webmaster
 
Join Date: Nov 2001
Location: Johor
Posts: 769
Rep Power: 101
hymns is on a distinguished road
Send a message via ICQ to hymns Send a message via Yahoo to hymns
ya ya
__________________
I hate when:

vBulletin Message:
Sorry! The administrator has specified that users can only post one message every 60 seconds
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
where to learn php ?? (something like tuition class..) Syazwan Website Programming 9 10-02-2006 05:49 PM
Multiple database class hajime Website Programming 4 02-09-2004 02:58 PM
Review pls.....My Class Website alltvmas Websites Review and Suggestion 12 20-06-2004 04:03 AM
#define class error dlm java prog ymhy_80 Website Programming 6 14-02-2004 12:01 AM
read me first - my class website(5 Amanah 2004) izah Websites Review and Suggestion 2 20-01-2004 02:31 PM


All times are GMT +8. The time now is 01:24 PM. Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0 vBulletin skin by ForumMonkeys.com.


WebmasterMalaysia.com is Proudly Hosted by Exabytes Semi Dedicated Server.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61