logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > PHP
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 09-20-2012, 07:54 PM   #1
tony09uk
 
Join Date: Oct 2010
Posts: 340
Default Trying to understand oop

I have started to play around with oop. I feel like im right back at the beggining again I have tried to put together a simple script but im already having problems.

Below I have added the whole thing that I wrote so someone can advise me on how to improve what im doing as well as help me with my current issue.

My issue is that i have given a couple of my methods two parameters and only the first one is returned, I have look on php.net and found only the first one can be returned, how do I go about returning two from one method? or would I have to create a method for each one e.g. one for hoo, one for cross etc?

Also are there any other ways I can improve this with regards to how I have create the last variable?

PHP Code:
class fighter {
                
                public function 
punch($hook$cross){
                    return 
$hook;
                    return 
$cross;
                }
                
                public function 
kick($round$front){
                    return 
$round;
                    return 
$front;
                }
                
                public function 
block($defence){
                    return 
$defence;
                }
                
            }
            
            
$tony = new fighter();
            
$kylie = new fighter();
            
            
$tPunch $tony->punch(1578);
            
$kPunch $kylie->punch(3025);
            
            
$tKick $tony->kick(4598);
            
$kKick $kylie->kick(4070);
            
            
$tBlock $tony->block(-50);
            
$kBlock $kylie->block(-50);
            
            
$tOverall $tPunch $tKick $tBlock;
            
$kOverall $kPunch $kKick $kBlock;
            
            echo 
$tOverall "<br />";
            echo 
$kOverall

Last edited by gentleone; 09-21-2012 at 02:28 PM.. Reason: code wrapped in PHP tags
tony09uk is offline   Reply With Quote
Old 09-21-2012, 02:27 PM   #2
gentleone
gentleone's Avatar
 
Join Date: Nov 2009
Location: Rhodes, Greece
Posts: 2,837
Default

Tony, you're around for a while now here at DWC, so you should know by now that it makes code much easier to read when you wrap your code in code, html or php tags in the advanced editor.
__________________
www.gentlemedia.nl
gentleone is offline   Reply With Quote
Old 09-21-2012, 04:45 PM   #3
Corrosive
Corrosive's Avatar
 
Join Date: Feb 2008
Location: Bristol, England
Posts: 7,103
Default

Good luck with that Tony. I've always struggled with the concept as well. I guess I should look at it again soon.
Corrosive is offline   Reply With Quote
Old 09-21-2012, 07:13 PM   #4
tony09uk
 
Join Date: Oct 2010
Posts: 340
Default

geentle one I had never even considered it, but i will start now. Any advice with my situation?
tony09uk is offline   Reply With Quote
Old 09-27-2012, 09:45 AM   #5
ruth_holloway
 
Join Date: Sep 2012
Posts: 1
Default

According to php manual, you can just return only one parameter. Besides php other programming languages doesn't support more than one parameter return.
ruth_holloway is offline   Reply With Quote
Old 09-27-2012, 01:25 PM   #6
tony09uk
 
Join Date: Oct 2010
Posts: 340
Default

Yeah I looked at that to, I guess i will have to get a better understanding of oop before starting to make anything with it
tony09uk is offline   Reply With Quote
Reply


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

Forum Jump


All times are GMT. The time now is 10:49 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com