Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 1681 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

Excercises for OOP beginners?

Thread title: Excercises for OOP beginners?
Closed Thread    
    Thread tools Search this thread Display Modes  
09-16-2007, 12:53 AM
#1
creativejen is offline creativejen
Status: Paladin
Join date: Jul 2006
Location: Sheffield, UK
Expertise: design, front-end markup
Software: Photoshop
 
Posts: 2,353
iTrader: 25 / 96%
 

creativejen is an unknown quantity at this point

Send a message via MSN to creativejen

  Old  Excercises for OOP beginners?

Ok, like a lot of people, i'm a beginner with OOP in php. I'm asking the very experienced people here, what sort of excercises or scripts to try and do first using OOP to better my knowledge?

09-16-2007, 07:55 AM
#2
Bursh. is offline Bursh.
Status: Member
Join date: Nov 2006
Location: In your bath.
Expertise:
Software:
 
Posts: 121
iTrader: 0 / 0%
 

Bursh. is on a distinguished road

Send a message via AIM to Bursh. Send a message via MSN to Bursh.

  Old

I would personally start of by making an object and writing members to change it's properties and then get used to calling those members from within the class and from outside the class.

IE

PHP Code:
class newClass
{
    public 
$property;
    
    function 
__construct($property)
    {
        
$this -> property $property;
    }

    public function 
changeProperty($property)
    {
        
$this -> property $property;
    }

    public function 
nullProperty()
    {
        
$this -> property $this -> changeProperty(NULL); #In this line we called the function we made before to change the property and supplied the null value for it.
    
}
}

$Obj = new newClass("Object 1");
echo 
"The current property is: ".$Obj -> property."<br />"// Outputs "The current property is: Object 1"

$Obj -> changeProperty("Object 1 V2");
echo 
"The current property is: ".$Obj -> property// Outputs "The current property is: Object 1 V2"

$Obj -> nullProperty();
echo 
"The currenty proprety is: ".$Obj -> property// Outputs "The current property is: " 
I hope that helped. The script should work - but knowing me and my lax syntax and error checking .. it might not

09-18-2007, 01:45 AM
#3
CreativeLogic is offline CreativeLogic
CreativeLogic's Avatar
Status: Request a custom title
Join date: Feb 2005
Location:
Expertise:
Software:
 
Posts: 1,078
iTrader: 6 / 100%
 

CreativeLogic is on a distinguished road

Send a message via MSN to CreativeLogic

  Old

You should note that his code that he wrote above is for PHP5, PHP4 lacks in OOP functionality.

09-18-2007, 01:46 AM
#4
Village Genius is offline Village Genius
Village Genius's Avatar
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
 
Posts: 6,894
iTrader: 18 / 100%
 

Village Genius will become famous soon enough

  Old

Stay away from PHP4, it is as a whole depreciated at this point.

For scripts, make any semi-large script and implement OOP on it, try a user system.

09-18-2007, 10:55 AM
#5
creativejen is offline creativejen
Status: Paladin
Join date: Jul 2006
Location: Sheffield, UK
Expertise: design, front-end markup
Software: Photoshop
 
Posts: 2,353
iTrader: 25 / 96%
 

creativejen is an unknown quantity at this point

Send a message via MSN to creativejen

  Old

Thanks for the comments, and Bursh: thanks for that, sorta helped.

09-18-2007, 04:16 PM
#6
Bursh. is offline Bursh.
Status: Member
Join date: Nov 2006
Location: In your bath.
Expertise:
Software:
 
Posts: 121
iTrader: 0 / 0%
 

Bursh. is on a distinguished road

Send a message via AIM to Bursh. Send a message via MSN to Bursh.

  Old

Originally Posted by iamAdam View Post
Thanks for the comments, and Bursh: thanks for that, sorta helped.
No problem

And yes, Creative Logic is right. That script is\was for PHP 5. Some of the keywords used aren't in PHP 4.

09-23-2007, 07:15 AM
#7
Kalle is offline Kalle
Status: I'm new around here
Join date: Apr 2007
Location: Denmark
Expertise:
Software:
 
Posts: 17
iTrader: 0 / 0%
 

Kalle is on a distinguished road

  Old

Originally Posted by Village Idiot View Post
Stay away from PHP4, it is as a whole depreciated at this point.

For scripts, make any semi-large script and implement OOP on it, try a user system.
For absolute beginners in OOP i would recommed them to look at the PHP4 tutorials as they give a basic and abit easier understanding of learning OOP in PHP and then move on to the differences in PHP5.

But in general i can only agree with staying away from PHP4 in general, but for learning basic OOP and testing it does the job

09-23-2007, 12:17 PM
#8
Haris is offline Haris
Status: Request a custom title
Join date: Dec 2005
Location:
Expertise:
Software:
 
Posts: 2,741
iTrader: 9 / 100%
 

Haris is on a distinguished road

  Old

Originally Posted by Kalle View Post
For absolute beginners in OOP i would recommed them to look at the PHP4 tutorials as they give a basic and abit easier understanding of learning OOP in PHP and then move on to the differences in PHP5.

But in general i can only agree with staying away from PHP4 in general, but for learning basic OOP and testing it does the job
I learned OOP with PHP5 and never had a problem.

Thanks to Village Idiot.

09-23-2007, 01:32 PM
#9
Village Genius is offline Village Genius
Village Genius's Avatar
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
 
Posts: 6,894
iTrader: 18 / 100%
 

Village Genius will become famous soon enough

  Old

Originally Posted by Kalle View Post
For absolute beginners in OOP i would recommed them to look at the PHP4 tutorials as they give a basic and abit easier understanding of learning OOP in PHP and then move on to the differences in PHP5.

But in general i can only agree with staying away from PHP4 in general, but for learning basic OOP and testing it does the job
PHP4 and 5 are almost identical till you get to some advanced concepts, although some basic concepts have better functionality. Why start a beginner on bad standards?

Closed Thread    


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

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed