From 3550730a9fb18bed62578a261e360dd9aaad6b2a Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Wed, 24 Apr 2024 23:16:47 +0400 Subject: [PATCH] bugs --- src/cl.php | 9 +++++++++ src/os/EOFException.php | 4 ++-- src/os/IOException.php | 4 ++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/cl.php b/src/cl.php index 6d57b73..eb9fcf7 100644 --- a/src/cl.php +++ b/src/cl.php @@ -141,6 +141,15 @@ class cl { return $array !== null? array_keys($array): []; } + /** + * retourner la première valeur de $array ou $default si le tableau est null + * ou vide + */ + static final function first($array, $default=null) { + if (is_array($array)) return $array[array_key_first($array)]; + return $default; + } + ############################################################################# /** diff --git a/src/os/EOFException.php b/src/os/EOFException.php index 8f8e2ea..0fc65fa 100644 --- a/src/os/EOFException.php +++ b/src/os/EOFException.php @@ -7,8 +7,8 @@ namespace nur\sery\os; */ class EOFException extends IOException { static final function ensure_not_eof($data, bool $throw=true, $eof=false) { - if (!$throw) return null; - elseif ($data !== $eof) return $data; + if ($data !== $eof) return $data; + elseif (!$throw) return null; else throw new self(); } } diff --git a/src/os/IOException.php b/src/os/IOException.php index 69fce1d..262b6e7 100644 --- a/src/os/IOException.php +++ b/src/os/IOException.php @@ -27,8 +27,8 @@ class IOException extends RuntimeException { } static final function ensure_valid($value, bool $throw=true, $invalid=false) { - if (!$throw) return null; - elseif ($value !== $invalid) return $value; + if ($value !== $invalid) return $value; + elseif (!$throw) return null; else throw self::error(); }