Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

bug or just my own incompetence?

3 views
Skip to first unread message

areisinger

unread,
May 16, 2007, 3:34:20 PM5/16/07
to
Hi all,
consider this content of test.php (PHP 5.2.1 installation on a
powweb.com server)

<?php
function logit (string $message)
{
echo "i´m here ";
}
mysql_query("foobar"); // ignore error message
logit(mysql_error());
?>

Ignoring the forced failure of mysql_query the following call to logit
brings this error message:

Catchable fatal error: Argument 1 passed to logit() must be an
instance of string, string given, called in ....... test.php

mysql_error should return string, logit requires string, where is the
real problem hidden?


best regards
a

PreZ

unread,
May 17, 2007, 3:18:41 AM5/17/07
to
Hy,

areisinger wrote:
> mysql_error should return string, logit requires string, where is the
> real problem hidden?

There is no string class in PHP, so mysql_error() returns a string ( a
chain of characters ), and the logit function requires an object which
is an instance of a "string" class. And it's absolutely not exists
there.

Regards,
Sandor Nemeth

fwd...@gmail.com

unread,
May 17, 2007, 5:18:40 AM5/17/07
to
Try this.

<?php
function logit ($message)

itn...@googlemail.com

unread,
May 17, 2007, 8:26:13 AM5/17/07
to

http://ch2.php.net/language.oop5.typehinting

"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."

Regards
i

areisinger

unread,
May 17, 2007, 10:59:06 AM5/17/07
to
Thank you very much, i found the "hint" in the docs after your answer:

"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."

http://php.net/manual/en/language.oop5.typehinting.php

Thanks for the answer

0 new messages