Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • php class vars auto instantiation using (PDO) ?

    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 86
    Answer it

    I'm creating an admin class and i need to know how to auto instantiating the class vars


        class Admin{
            public $admin_id ;
            public $admin_name ;
            public $admin_email ;
            public $admin_type ;
            public $admin_password ;
            // methods goes here
            $admin = new Admin();
            $class_vars = get_class_vars(get_class($admin));
            foreach ($class_vars as $name => $value) {
                     echo "$name : $value<br />";


    in some of lynda tutorial (php beyond the basic ) you have to create couple of methods so you can instantiation the class vars using mysqli


    private static function instantiation($database_row){
            $object = new self ; 
            foreach($database_row as $attribute => $value){
                    $object->$attribute = $value ;
            return $object;
    private function  has_attribute($attribute){
    $object_properties = get_object_vars($this);
    return array_key_exists($attribute,$object_properties);


    but i need to use the pdo instead of mysqli

 1 Answer(s)

  • Hello Nasyia,

    I just reviewed your code. You can use same code with PDO connection. You need to study the PDO syntax and functions. Kindly check our blogs on PDO.

    Thank you

    Deepak Verma
Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: