PHP Velho Oeste 2024

Examplo que exibe o efeito do scream

Esse exemplo demonstra como o scream afeta o comportamento do manipulador de erros do PHP.

Exemplo #1 Habilitando e desabilitando o scream em tempo de execução

<?php
// Make sure errors will be shown
ini_set('display_errors'true);
error_reporting(E_ALL);

// Disable scream - this is the default and produce an error
ini_set('scream.enabled'false);
echo 
"Opening http://example.com/not-existing-file\n";
@
fopen('http://example.com/not-existing-file''r');

// Now enable scream and try again
ini_set('scream.enabled'true);
echo 
"Opening http://example.com/not-existing-file\n";
@
fopen('http://example.com/not-existing-file''r');
?>

O exemplo acima irá imprimir algo similar à:

Opening http://example.com/not-existing-file
Opening http://example.com/not-existing-file

Warning: fopen(http://example.com/not-existing-file): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in example.php on line 14

Nota: Normalmente deve-se definir isso no arquivo de configuração php.ini ao invés de mudar o código.

add a note add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top