OOP in php, object structure, handling

Links for php scripts

Moderators: egami, macek, gesf

Post Reply
iago
php-forum Active User
php-forum Active User
Posts: 41
Joined: Thu Mar 26, 2020 2:33 pm

Thu Dec 17, 2020 1:36 am

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
User avatar
CodesbyKelvin
New php-forum User
New php-forum User
Posts: 1
Joined: Wed Dec 30, 2020 11:35 am

Wed Dec 30, 2020 12:27 pm

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
User avatar
Strider64
php-forum GURU
php-forum GURU
Posts: 418
Joined: Sat Mar 23, 2013 8:24 am
Location: Livonia, MI
Contact:

Wed Dec 30, 2020 3:04 pm

That will probably will lead to polymorphism which could lead to problems. I think there is a better way in writing that.
Life is a fig newton of your imagination! https://www.miniaturephotographer.com
Post Reply