Error messages
am 28.08.2007 15:46:41 von Zanna
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
Re: Error messages
am 28.08.2007 16:08:09 von zeldorblat
On Aug 28, 9:46 am, "Fabio" 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.
Re: Error messages
am 28.08.2007 16:20:21 von Zanna
"ZeldorBlat" ha scritto nel messaggio
news:1188310089.122831.307840@50g2000hsm.googlegroups.com...
> 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.
???
I tryied with
$a = "hi";
foo($a);
but is the same... at this point I don't understand how to remove this kind
or error message.
> Take that out of your function
> declaration and it should be fine.
so I should remove the type for the parameter?
This don't seems a good solution :(
I tryied this kind of error_reporting because else if I declare for my fault
2 time the foo() function, the script is interrupted (cannot be interpreted)
and I got the error message that the function is duplicated.
I was not able to leave the useful "duplicated error message" but removing
the useless *catchable* FATAL (???) error :(
Re: Error messages
am 28.08.2007 16:31:32 von Joe Scylla
Fabio wrote:
> ...snipped...
>
>> Take that out of your function
>> declaration and it should be fine.
>
> so I should remove the type for the parameter?
> This don't seems a good solution :(
>
> I tryied this kind of error_reporting because else if I declare for my fault
> 2 time the foo() function, the script is interrupted (cannot be interpreted)
> and I got the error message that the function is duplicated.
>
> I was not able to leave the useful "duplicated error message" but removing
> the useless *catchable* FATAL (???) error :(
Please read the manual about Type Hinting:
http://www.php.net/manual/en/language.oop5.typehinting.php
Joe
Re: Error messages
am 29.08.2007 01:55:21 von Michael Fesser
..oO(Fabio)
>One question.
>
>I set to php.ini this
>
>error_reporting=E_ALL & ~E_NOTICE
Should be E_ALL.
>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);
>}
Should be
function foo($x) {
echo $x;
}
Micha
Re: Error messages
am 29.08.2007 23:51:28 von Zanna
"Joe Scylla" ha scritto nel messaggio
news:fb1bfi$676$01$2@news.t-online.com...
>>
>> I was not able to leave the useful "duplicated error message" but
>> removing the useless *catchable* FATAL (???) error :(
>
> Please read the manual about Type Hinting:
> http://www.php.net/manual/en/language.oop5.typehinting.php
>
This seems a really bad implementation of php.
Php let you indicate the data type to be used and then considers it as a
syntax error???
Good thing...
Re: Error messages
am 29.08.2007 23:54:15 von Zanna
"Michael Fesser" ha scritto nel messaggio
news:obd9d35ij3do3lj5olnbmnu6kl7h9eui3p@4ax.com...
>
> Should be E_ALL.
>
I find the best to write good code:
E_ALL | E_STRICT & ~E_RECOVERABLE_ERROR
The classic problem is that the php online documentation is really
incomplete and confused: the E_RECOVERABLE_ERROR is not documented, but I
can find something more in the donloaded documentation or in some unofficial
web site.
Re: Error messages
am 30.08.2007 05:43:32 von Jerry Stuckle
Fabio wrote:
> "Joe Scylla" ha scritto nel messaggio
> news:fb1bfi$676$01$2@news.t-online.com...
>
>
>>> I was not able to leave the useful "duplicated error message" but
>>> removing the useless *catchable* FATAL (???) error :(
>> Please read the manual about Type Hinting:
>> http://www.php.net/manual/en/language.oop5.typehinting.php
>>
>
> This seems a really bad implementation of php.
> Php let you indicate the data type to be used and then considers it as a
> syntax error???
>
> Good thing...
>
>
It allows you to indicate a *USER DEFINED* data type. Not a built-in
datatype.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: Error messages
am 30.08.2007 06:55:02 von Michael Fesser
..oO(Fabio)
>This seems a really bad implementation of php.
>Php let you indicate the data type to be used and then considers it as a
>syntax error???
The manual is pretty clear about that:
| Type Hints can only be of the object and array (since PHP 5.1) type.
| Traditional type hinting with int and string isn't supported.
Or in other words - it works for complex types, but not for scalars.
Micha
Re: Error messages
am 30.08.2007 07:00:53 von Michael Fesser
..oO(Fabio)
>I find the best to write good code:
>
>E_ALL | E_STRICT & ~E_RECOVERABLE_ERROR
IMHO that's even worse than supressing E_NOTICE errors. _All_ errors
should be shown and handled while developing, which means
E_ALL
or better
E_ALL | E_STRICT
Micha