Jak vytvořit return true/false
Ahoj, jak bych mohl doplnit tuto funkci o return true / false, pokud cokoli selže tak false a pokud je všechno ok tak true. Může někdo poradit?
function write (){
$file = 'people.txt';
$current = file_get_contents($file); // Open the file to get existing content
$current .= "John Smith\n"; // Append a new person to the file
file_put_contents($file, $current); // Write the contents back to the file
}
Díky pane a je možnost i bez použití vyjímky byť třeba jen s jedním returnem?
Na otevírání a práci se soubory, vždy používat TRY/CATCH. Samozřejmě tu funkci ještě musíš deklarovat jako "bool".
A jak se taková funkce deklaruje jako bool? Tím, že vrací true nebo false přece return bool je, ne?
Díky moc.