View Full Version : Trying to understand oop

09-20-2012, 07:54 PM
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?

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(15, 78);
$kPunch = $kylie->punch(30, 25);

$tKick = $tony->kick(45, 98);
$kKick = $kylie->kick(40, 70);

$tBlock = $tony->block(-50);
$kBlock = $kylie->block(-50);

$tOverall = $tPunch + $tKick + $tBlock;
$kOverall = $kPunch + $kKick + $kBlock;

echo $tOverall . "<br />";
echo $kOverall;

09-21-2012, 02:27 PM
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.

09-21-2012, 04:45 PM
Good luck with that Tony. I've always struggled with the concept as well. I guess I should look at it again soon.

09-21-2012, 07:13 PM
geentle one I had never even considered it, but i will start now. Any advice with my situation?

09-27-2012, 09:45 AM
According to php manual, you can just return only one parameter. Besides php other programming languages doesn't support more than one parameter return.

09-27-2012, 01:25 PM
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 :D