Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 07-31-2002, 06:23 PM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
OOP with PHP

as some of you know, i'm working on a new bbs. last night i ported the functions i have into a class .. i'm really enjoying object oriented programming with php.

here's an example:
PHP Code:
<?
class user
{     
     
set_name($username)     
     {         
           
$this->username=$username;     
     }
}

$me = new user();
$you = new user();

$me->set_name("mike");
$you->set_name("joe schmoe");

echo 
"my name is " $me->username;
echo 
"your name is " $you->username;

?>
cool stuff!
sde is offline   Reply With Quote
Old 08-01-2002, 01:42 PM   #2 (permalink)
technobard
Centurion Nova Prime
 
technobard's Avatar
 
Join Date: May 2002
Location: Oak Park, IL (USA)
Posts: 285
technobard is on a distinguished road
Cool! I noticed that it doesn't have a constructor. Is this an option? I'd be curious to know the limits and capabilities. I don't remember if you also had java experience (or C++), but a comparison of the two in terms of object-oriented features would be great. Might even make a nice NUM.
technobard is offline   Reply With Quote
Old 08-01-2002, 02:09 PM   #3 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
yes, you can use a constructor =)

I think it's even proper to define variables in the class first, but not necessary.

From what i've researched, there is no distinction between public and private members of the class. They all seem to be public.

Here's how the constructor would work.
PHP Code:
<?
class user
{    
      function 
user
     
{
          
$this->name=$username;
     }
}

$me = new user("mike");
$you = new user("joe schmoe");



echo 
"my name is " $me->name;
echo 
"your name is " $you->name;

?>
currently i'm working on a new look and feel for the site as well as new forums .. i will create a new num after this change.
sde is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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
PHP Comes of Age sde Code Newbie News 0 04-14-2004 11:41 AM
new to php jhoop2002 PHP 12 08-06-2003 02:45 PM
I need to learn PHP Nitro PHP 9 06-28-2003 11:24 AM
Php Vs. Asp sde PHP 6 06-06-2003 06:02 PM
PHP as CGI?? bdl PHP 8 05-08-2003 08:29 AM


All times are GMT -8. The time now is 06:53 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting