在PHP中使用PSR4命名自动加载

I have following library structure

C:\WWW\WEBS
|   users.php
|
\---lib
    |   Api.php
    |   Server.php
    |   TimeSync.php
    |
    \---TimeSync
            Ntp.php
            Protocol.php
            Sntp.php

In server.php I have

<?php
namespace lib; 
class Server extends Api
{
}
?>

In users.php I am using it as

<?php
  use lib\Server;
  $objServer = new Server();
?>

I also tried it using like use lib\Server;

But in both cases it is saying

Fatal error: Class 'lib\Server' not found in

C:\www\Experimentation\webserviceserver\users.php on line 7

Where I am going wrong .Should I user a autoloader?

You will need to use an autoloader. You can use the one delivered in Composer. Once you've installed it (at the root of your project), you put a composer.json file, and inside you copy the following code :

 {
    "autoload":{
        "psr-4":{
            "Lib\\" : "lib/"
        }
    }
 }

Then you use the command composer dumpautoload. That will copy the autoloading files in a folder named "vendor" at the root of your project.

Then in users.php you require the autoloader :

require_once "vendor/autoload.php"

And you use the namespacing :

use Lib;
$objServer = new Lib\Server();

It might work.