[PHP] Human class.

Results 1 to 10 of 10
  1. #1
    The Gamma..? EliteGM is offline
    MemberRank
    Jul 2006 Join Date
    NandolandLocation
    4,078Posts

    [PHP] Human class.

    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 Code:
    <?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
    Tell me what u think!


  2. #2
    Account Upgraded | Title Enabled! Daney is offline
    MemberRank
    Jun 2007 Join Date
    1,110Posts

    Re: [PHP] Human class.

    Very simple, are you just learning PHP? - If so this is quite good. Easy but good for a beginner.

  3. #3
    The Gamma..? EliteGM is offline
    MemberRank
    Jul 2006 Join Date
    NandolandLocation
    4,078Posts

    Re: [PHP] Human class.

    Well I'm not really learning php, Im actually pretty good at it.
    But this script was posted in another thread and then (if im board~) my brains start running and I just have to improve/fix it :P

  4. #4
    Member G_NETWORK is offline
    MemberRank
    Aug 2007 Join Date
    In a box :PLocation
    87Posts

    Re: [PHP] Human class.

    Lol, you made this in other thread becuase i started with a simple function (the guy wanted a human) :P

    It's nice :D

  5. #5
    Account Upgraded | Title Enabled! andrew951 is offline
    MemberRank
    Dec 2006 Join Date
    207Posts

    Re: [PHP] Human class.

    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.

  6. #6
    The Gamma..? EliteGM is offline
    MemberRank
    Jul 2006 Join Date
    NandolandLocation
    4,078Posts

    Re: [PHP] Human class.

    It is simple to do it like that, but the point of this script is: that I don't want it simple :P

  7. #7
    Member Vineyard is offline
    MemberRank
    Jul 2008 Join Date
    FinlandLocation
    53Posts

    Re: [PHP] Human class.

    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 ;)

  8. #8
    :-) s-p-n is offline
    DeveloperRank
    Jun 2007 Join Date
    Next DoorLocation
    2,098Posts

    Re: [PHP] Human class.

    Lol! Okay I got the timeline before you made this thread, starting with me telling a bad joke:
    Quote Originally Posted by s-p-n View Post
    ...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?
    Quote Originally Posted by G_NETWORK View Post
    PHP Code:

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

    "Add your lifeline here"

    }

    New 
    human => human(Bob,male,18



    Quote Originally Posted by s-p-n View Post
    Haha.. something can be done with that..
    PHP Code:
     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)>&& strlen($sex)>&& strlen($name)>0) {

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

    } else {

    human(Bob,guy,18);


    lol.. I dunno..
    Quote Originally Posted by EliteGM View Post
    UPDATED Human :



    PHP Code:

       <?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

  9. #9
    Account Upgraded | Title Enabled! Thesnowman is offline
    MemberRank
    Nov 2007 Join Date
    423Posts

    Re: [PHP] Human class.

    The link took me to google.nl haha

  10. #10
    The Gamma..? EliteGM is offline
    MemberRank
    Jul 2006 Join Date
    NandolandLocation
    4,078Posts

    Re: [PHP] Human class.

    Quote Originally Posted by Thesnowman View Post
    The link took me to google.nl haha
    Yeah because of some bandwith problems I took it down =[



Advertisement