1
0
mirror of https://github.com/danielstjules/Stringy.git synced 2025-08-12 08:14:06 +02:00

Implicit cast argument to string in constructor

This commit is contained in:
gotterdemarung
2013-12-10 22:15:58 +02:00
parent 75404a0338
commit 88d5973701

View File

@@ -15,10 +15,21 @@ class Stringy
* *
* @param string $str String to modify * @param string $str String to modify
* @param string $encoding The character encoding * @param string $encoding The character encoding
*
* @throws \InvalidArgumentException if array or resource passed to constructor instead of string
*/ */
public function __construct($str, $encoding = null) 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(); $this->encoding = $encoding ?: mb_internal_encoding();
} }