<?php

class Fillable{
    public static function fill($props)
    {
        $cls = new static;
        foreach($props as $key=>$value){
            if (property_exists(static::class,$key)){
                $cls->$key = $value;
            }
        }
        return $cls;
    }
}
class Vegetable extends Fillable
{

    public $edible;
    public $color;
}

$veg = Vegetable::fill([
    'edible' => true,
    'color' => 'green',
    'name' => 'potato' //Will not get set as it's not a property of Vegetable. (you could also throw an error/warning here)
]);

var_dump($veg);