PHP code example of snapshotpl / status-code

1. Go to this page and download the library: Download snapshotpl/status-code library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

snapshotpl / status-code example snippets


$statusCode = new StatusCode(404);

$statusCode->isClientError(); // true
$statusCode->isRfc2516() // true
$statusCode->isServerError(); // false

echo $statusCode; // 404 Not Found

$response = new Zend\Diactoros\Response();
$statusCode = StatusCode::createFromResponse($response);
echo $statusCode; // 200 OK

$response = new Zend\Diactoros\Response();
$statusCode = new StatusCode(404, 'Not exists');
$newResponse = $statusCode->attachToResponse($response);
echo $newResponse->getStatusCode(); // 404
echo $newResponse->getReasonPhrase(); // Not exists