PHP code example of rumd3x / php-go-errors

1. Go to this page and download the library: Download rumd3x/php-go-errors 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/ */

    

rumd3x / php-go-errors example snippets



Rumd3x\Errors\Error;


$result = exampleFunction();

if ($result instanceof Error) {
    echo "$result\n";
    exit 1;
}

echo "File contents:\n";
foreach ($data as $row) {
    echo "$row\n";
}

/**
 * The example function
 */
function exampleFunction() {
    $data = file('filename.txt');

    if ($data === false) {
        return Error::new('failed to open file');
    }

    return $data;
}

$err = new ErrorImplementation('error message');

$err = new ErrorImplementation('error message');
echo $err->error();

$err = Error::new('error message');

$err = Error::newf('error: %d is %s than %d', 10, 'less', 20);

$err = Error::new('error message');
$text = $error->error(); // $text should contain 'error message'
$text2 = (string) $error; // $text2 should also contain 'error message'
echo $err; // should output 'error message'
echo "Error: $err"; // should output 'Error: error message'