<?php 
require_once("initPDO.php"); 

class User{
    /*private static function _initInstances(){
        global $pdo;
        if (!isset(self::$_instances)) {
            $request = $pdo->prepare("select * from users");
            $request->execute();
            self::$_instances = [];
            while($line = $request->fetch()){
                $_instances[] = $line;
            }
            print_r($_instances);
        }
    }*/

    private static function getAllUsers(){
        global $pdo;
        $request = $pdo->prepare("select * from users");
        $request->execute();
        $request->setFetchMode(PDO::FETCH_CLASS, get_called_class());
        $users = $request->fetchAll();
        return $users;
    }
    public static function showAllUsersAsTable(){
        $str="<table>
        <tr>
            <th>User</th>
            <th>email</th>
        </tr>";
        foreach (static::getAllUsers() as $value) {
            $str.=$value->toHtml();
        }
        $str.='
                
            </body>
            </html>';
        echo $str;
    }

    private function toHtml(){
        return "<tr>
        <td>$this->name</th>
        <td>$this->email</th>
        </tr>";
    }
}