Jump to content

learning OOP please help.


redarrow

Recommended Posts

I am trying to learn OOP, and i have created this crap,

i  want to no what it all about cheers?

 

 

 

<?php

class Life_Story {

function about_me($my_arms,$my_legs,$my_disabilty){

echo" The number of legs i got is\n$my_legs and the number
of arms i got is\n$my_arms i also got a disabilty in my\n$my_disabilty";

}

}
$Life_Story = new Life_Story();
$Life_Story -> about_me($my_arms=2,$my_legs=2,$my_disabilty="eyes");
?>

 

 

 

i get what the oop is doing, but don't understand where to use this type off programming and how to, please help.

 

 


<?php

class Life_Story {


function about_me($my_arms,$my_legs,$my_disabilty){

echo" The number of legs i got is\n$my_legs and the number
of arms i got is\n$my_arms i also got a disabilty in my\n$my_disabilty";

}

}

$Life_Story = new Life_Story();
$Life_Story -> about_me($my_arms=2,$my_legs=2,$my_disabilty="eyes");

$Life_Story2 = new Life_Story();
$Life_Story2 -> about_me($my_arms=1,$my_legs=2,$my_disabilty="head");
?>

Link to comment
https://forums.phpfreaks.com/topic/173216-learning-oop-please-help/
Share on other sites

OOP is one of those things you learn more about by doing.

 

I would suggest you have a read of some texts on OOP and design patterns to see where real world comes in to play.

 

http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612 is apparently a ubiquitous text.

 

I would also recommend http://www.amazon.com/PHP-Architects-Guide-Design-Patterns/dp/0973589825 - old book but I found it useful.

 

As you progress you will find more resources and I'm sure others will contribute valuable resources if asked.

 

Good luck with it fella - once you get into OOP you won't look back.

what the flow, to cheek a username to a var set username within a class from a form posted then cheers.

 

 

example

 

say i use this code, to see the oop form, and i want to match the set var name of username from the oop to match the name entred in a form how that done cheers.

 

<?php



if(isset($_POST['submit'])){

$username=$_POST['username'];

if($username==Message_Users()->$username){

	echo correct;

	exit;
}
}



class Message_Users{

var $username="redarrow";

var $password="redarrow";

function form(){

echo"<form method='POST'>
username
<br />
<input type='text' name='username'>
<br />
password
<br />
<input type='password' name='password'>
<br /><br />
<input type='submit' name='submit' value='SEND!'>
</form>";
}

}

$Message_Users= new message_Users(); 

$Message_Users->form();


?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.