From 88d597370185880a9b9f2002cfb9cd17cf8244dc Mon Sep 17 00:00:00 2001 From: gotterdemarung Date: Tue, 10 Dec 2013 22:15:58 +0200 Subject: [PATCH] Implicit cast argument to string in constructor --- src/Stringy/Stringy.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Stringy/Stringy.php b/src/Stringy/Stringy.php index c152154..9c41ea5 100644 --- a/src/Stringy/Stringy.php +++ b/src/Stringy/Stringy.php @@ -15,10 +15,21 @@ class Stringy * * @param string $str String to modify * @param string $encoding The character encoding + * + * @throws \InvalidArgumentException if array or resource passed to constructor instead of string */ public function __construct($str, $encoding = null) { - $this->str = $str; + if (is_array($str)) { + throw new \InvalidArgumentException( + 'Expecting string, array given' + ); + } else if (is_resource($str)) { + throw new \InvalidArgumentException( + 'Expecting string, resource given' + ); + } + $this->str = (string) $str; $this->encoding = $encoding ?: mb_internal_encoding(); }