PHP code example of margusk / warbsorber

1. Go to this page and download the library: Download margusk/warbsorber 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/ */

    

margusk / warbsorber example snippets


use function margusk\Warbsorber;

$fopenWarnings = Warbsorber(function () use (&$fp) {
    $fp = fopen("php://non-existent-stream", "r");
});

if (!$fp) {
    echo "fopen() failed with messages: \n";

    foreach ($fopenWarnings as $entry) {
        echo "- " . $entry->errStr . "\n";
    }
}

use function margusk\Warbsorber;

$fopenWarnings = Warbsorber(function () use (&$fp) {
    $fp = fopen("php://non-existent-stream", "r");
});

if (!$fp) {
    $fopenWarnings = $fopenWarnings->removeFunctionPrefix('fopen');

    echo "fopen() failed with: "
        .implode(
            '. ',
            array_map(
                fn(Entry $e) => $e->errStr,
                $fopenWarnings->getArrayCopy()
            )
        )
        .".\n";
}

use function margusk\Warbsorber;

$fopenWarnings = Warbsorber(function () use (&$fp) {
    $fp = fopen("php://non-existent-stream", "r");
}, E_WARNING | E_NOTICE | E_DEPRECATED);
bash
fopen() failed with messages:
- fopen(): Invalid php:// URL specified
- fopen(php://non-existent-stream): Failed to open stream: operation failed
bash
fopen() failed with: Invalid php:// URL specified. Failed to open stream: operation failed.