[PHP] Human class.

Joined
Jul 26, 2006
Messages
3,626
Reaction score
1,006
The script is simple to the eye, but code is more complicated :P
You can extend this even to what the license plate number of him is, it doesn't take too much knowledge to do that, rather to set the basics.

PHP:
<?php
class Human
{
	var $First;
	var $Name;
	var $Middle;
	var $Last;
	var $Sex;
	var $Age;
		
	function Human($first, $middle, $last, $sex, $age)
	{
		$this->Name   = $first;
		$this->First  = $first;
		$this->Middle = $middle;
		$this->Last   = $last;
		$this->Sex    = $sex;
		$this->Age    = $age;
	}
	
	function Human_fullName()
	{
		if (empty($this->Middle))
		{
			$fullName = $this->First .' '. $this->Last;
		} else {
			$fullName = $this->First .' '. $this->Middle .' '. $this->Last;
		}
		return $fullName;
	}
	
	function Human_show($name, $sex, $age)
	{
		$fullName = $this->Human_fullName();
		echo '<h3><i>About Me..</i></h3>';
		echo '<p>My name is '.$fullName.', you can call me '.$name.' for short.';
		echo '<br>';
		echo 'I am '.$age.' years old.';
		echo '<br>';
		echo 'You probably already know due to my name, but I happen to be a '.$sex.'.</p>';
	}
	
	function Human_update_show($first, $middle, $last, $sex, $age) 
	{
		echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">';
			echo '<table border="0">';
			echo '<td>First Name: </td><td><input name="name" value="'.$first.'" type="text" /></td></tr>';
			echo '<tr><td>Middle Name: </td><td><input name="mname" value="'.$middle.'" type="text" /></td></tr>';
			echo '<tr><td>Last Name: </td><td><input name="lname" value="'.$last.'" type="text" /></td></tr>';
			echo '<tr><td>Age: </td><td><input name="age" value="'.$age.'" type="text" /></td></tr>';
			echo '<tr><td>Gender: </td>';
			echo '<td><select name="sex" selected="'.$sex.'">';
			echo '<optgroup label="Gender">';
			echo '<option value="Male">Male</option>';
			echo '<option value="Female">Female</option>';
			echo '</optgroup>';
			echo '</select>';
			echo '</td></tr>';
			echo '<tr><td></td><td><input type="submit" name="create" value="Update Human!" /></td></tr>';
			echo '</table>';
		echo '</form>';
	}
}

if ($_POST['create'])
{
	$Human = new Human($_POST['name'], $_POST['mname'], $_POST['lname'], $_POST['sex'], $_POST['age']);
} else {
	$Human = new Human('Bob', '', 'Bobkinsons', 'Male', 22);
}

$Human->Human_show($Human->Name, $Human->Sex, $Human->Age);
$Human->Human_update_show($Human->First, $Human->Middle, $Human->Last, $Human->Sex, $Human->Age);

?>

And: http://runeweb.thamob.nl/test2.php :thumbup1:
Tell me what u think!
 
i think it could have been simpler. just like echo from mysql and use the form to update. haha.
but thats because i dont know much about php. lol.
 
I personally don't like PHP4's oop engine based code... Which hasn't even been done with the general conventions.
(maybe I'm just whining but: class names Capitalized, variable and function names camelCased. In php5, variables _should_ be private and have corresponding get&set functions. Class constructor is __construct() overloading function)... Well, good job otherwise, I'd say that it demonstrated OOP pretty well being a Human object ;)
 
Lol! Okay I got the timeline before you made this thread, starting with me telling a bad joke:
...But I think it needs a human in the back-end to pick and choose the right answers for the right questions.. Can anyone make me a human in PHP?

PHP:
Function Human($name,$sex,$age) {

"Add your lifeline here"

}

New human => human(Bob,male,18)




Haha.. something can be done with that..
PHP:
 Function human($name,$sex,$age) {

list($a_name['first'],$a_name['mid'],$a_name['last']) = split(' ',$name);

echo '<h3><i>About Me..</i></h3>';

echo '<p>My name is '.$name.', you can call me '.$a_name['first'].' for short.';

echo '<br>';

echo 'I am '.$age.' years old.';

echo '<br>';

echo 'You probably already know due to my name, but I happen to be a '.$sex.'.</p>';

}

 

function updateHuman($name,$sex,$age) {

echo '<form action="index.php" method="post">';

echo 'Name: <input name="name" value="'.$name.'" type="text" /> <small><i>(first, middle, last)</i></small>';

echo '<br>';

echo 'Age: <input name="age" value="'.$age.'" type="text" />' ;

echo '<br>';

echo 'Gender: <input name="sex" value="'.$sex.'" type="text" />';

echo '<br>';

echo '<input type="submit" name="create" value="Update Human!" />';

echo '</form>';

}

 

$name = $_POST['name'];

$sex = $_POST['sex'];

$age = $_POST['age'];

 

updateHuman($name,$sex,$age);

 

if(strlen($age)>0 && strlen($sex)>0 && strlen($name)>0) {

human($name,$sex,$age);

} else {

human(Bob,guy,18);

}
lol.. I dunno..

UPDATED Human :



PHP:
   <?php

class Human

{

    var $First;

    var $Name;

    var $Middle;

    var $Last;

    var $Sex;

    var $Age;

 

    function Human($first, $middle, $last, $sex, $age)

    {

        $this->Name   = $first;

        $this->First  = $first;

        $this->Middle = $middle;

        $this->Last   = $last;

        $this->Sex    = $sex;

        $this->Age    = $age;

    }

 

    function Human_fullName()

    {

        if (empty($this->Middle))

        {

            $fullName = $this->First .' '. $this->Last;

        } else {

            $fullName = $this->First .' '. $this->Middle .' '. $this->Last;

        }

        return $fullName;

    }

 

    function Human_show($name, $sex, $age)

    {

        $fullName = $this->Human_fullName();

        echo '<h3><i>About Me..</i></h3>';

        echo '<p>My name is '.$fullName.', you can call me '.$name.' for short.';

        echo '<br>';

        echo 'I am '.$age.' years old.';

        echo '<br>';

        echo 'You probably already know due to my name, but I happen to be a '.$sex.'.</p>';

    }

 

    function Human_update_show($first, $middle, $last, $sex, $age) 

    {

        echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">';

            echo '<table border="0">';

            echo '<td>First Name: </td><td><input name="name" value="'.$first.'" type="text" /></td></tr>';

            echo '<tr><td>Middle Name: </td><td><input name="mname" value="'.$middle.'" type="text" /></td></tr>';

            echo '<tr><td>Last Name: </td><td><input name="lname" value="'.$last.'" type="text" /></td></tr>';

            echo '<tr><td>Age: </td><td><input name="age" value="'.$age.'" type="text" /></td></tr>';

            echo '<tr><td>Gender: </td>';

            echo '<td><select name="sex" selected="'.$sex.'">';

            echo '<optgroup label="Gender">';

            echo '<option value="Male">Male</option>';

            echo '<option value="Female">Female</option>';

            echo '</optgroup>';

            echo '</select>';

            echo '</td></tr>';

            echo '<tr><td></td><td><input type="submit" name="create" value="Update Human!" /></td></tr>';

            echo '</table>';

        echo '</form>';

    }

}

 

if ($_POST['create'])

{

    $Human = new Human($_POST['name'], $_POST['mname'], $_POST['lname'], $_POST['sex'], $_POST['age']);

} else {

    $Human = new Human('Bob', '', 'Bobkinsons', 'Male', 22);

}

 

$Human->Human_show($Human->Name, $Human->Sex, $Human->Age);

$Human->Human_update_show($Human->First, $Human->Middle, $Human->Last, $Human->Sex, $Human->Age);

 

?>


Just so everyone knows where you're coming from.. Which is, my bad joke :P:
 
Back