OOP 101 - quick question.

Posted by R Bennett on Stack Overflow See other posts from Stack Overflow or by R Bennett
Published on 2010-06-17T15:55:56Z Indexed on 2010/06/17 16:03 UTC
Read the original article Hit count: 334

Filed under:
|

I've used procedural for sometime now and trying to get a better understanding of OOP in Php. Starting at square 1 and I have a quick question ot get this to gel. Many of the basic examples show static values ( $bob->name = "Robert";) when assigning a value, but I want to pass values... say from a form ( $name = $_POST['name']; )

class Person { 

    // define properties 
    public $name; 
    public $weight; 
    public $age;

    public function title() { 
        echo $this->name . " has submitted a request "; 
    }
} 

$bob = new Person; 

// want to plug the value in here
$bob->name = $name; 
$bob->title();

I guess I'm getting a little hung up in some areas as far as accessing variables from within the class, encapsulation & "rules", etc., can $name = $_POST['name']; reside anywhere outside of the class or am I missing an important point?

Thanks

© Stack Overflow or respective owner

Related posts about php

Related posts about oop