|
Posted by ZeldorBlat on 08/28/07 14:08
On Aug 28, 9:46 am, "Fabio" <znt.fa...@virgilio.it> wrote:
> Hi,
>
> One question.
>
> I set to php.ini this
>
> error_reporting=E_ALL & ~E_NOTICE
>
> to be a list of error messages and some warnings/tips on the code written.
>
> All good, but if I have code like
>
> ------------------------
> function foo(string $x)
> {
> echo($x);
>
> }
>
> foo("hi");
> ------------------------
>
> I got this error
>
> ------------------------
> Catchable fatal error: Argument 1 passed to foo() must be an instance of
> string, string given, called in E:\Work\php\phpFramework\test.php on line 8
> and defined in E:\Work\php\phpFramework\test.php on line 3
> ------------------------
>
> !!!but... is not "hi" a string???
> What kind of *Catchable fatal error* would be this???
>
> :)
>
> I write foo(string $x) exactly to say that the function need a string!
>
> Thanks
The type hinting is for objects and arrays only. So, with the code
you've got, PHP expects the argument to be an object of class "string"
rather than the primitive string. Take that out of your function
declaration and it should be fine.
Navigation:
[Reply to this message]
|