OOP in php, object structure, handling

Links for php scripts

Moderators: gesf, Michalio

Post Reply
iago

Hello,
I have the following object handling from a tutorial and I don't understand why the object is passed to another variable and then the other variable is then used as the referent? (by the way I get an error message when I do it like that)

Code: Select all

if(Input::exists()) {
 if(Token::check(Input::get('token'))) {
    

    $validate = new Validate();
    $validation = $validate->check($_POST,array('name'=>array(
        'required' => true,
        'min' => 2,
        'max' => 50

    )
));

    if($validation->passed()) {

        //update
    } else {

        foreach($validation->errors() as $error) {

            echo $error, '<br/>';
        }
    }
 }
Why is $validation used here?
I just use $validate then but it would intersting if there is something behind the construction?

Thanks, iago
CodesbyKelvin

My best guess is:

The contructor of Validate class calls a static function that probably has the same naming convention

The object returned by $validate->check will make more sense if named validation
Strider64

That will probably will lead to polymorphism which could lead to problems. I think there is a better way in writing that.
Post Reply