Page 1 of 1

Types, Type Hinting, Casting

Posted: Wed Dec 30, 2009 7:50 am
by kaisellgren
I'm a bit confused, when will PHP support type hinting? I thought 5.3 was supposed to support parameter type hinting, but apparently not.

I am also wondering what you guys do when you have a situation where a method returns binary data. Do you define the return type to be binary or string or what? For example:

Code: Select all

/**
* @return binary
*/
function something()
{
 return (binary) $something;
}
or do you just use string (since there is no binary type)? What about situations where you accept string/binary data for a parameter, do you use string, binary or mixed? I'm talking about the PHPDoc syntax @param and @return that specifies the type.

The difference between binary and string is simple: a string is encoded in Unicode in PHP 6+.

Oh and if anyone is running PHP 6, can you confirm that

Code: Select all

echo strlen((string) ((binary) "è"));
returns 1?

Re: Types, Type Hinting, Casting

Posted: Wed Dec 30, 2009 8:34 am
by jason

Re: Types, Type Hinting, Casting

Posted: Wed Dec 30, 2009 9:22 am
by kaisellgren
It doesn't really tell anything, or are you hinting at some comments?

Re: Types, Type Hinting, Casting

Posted: Wed Dec 30, 2009 9:27 am
by jason
It was just in response to your first question about type hinting.
I'm a bit confused, when will PHP support type hinting? I thought 5.3 was supposed to support parameter type hinting, but apparently not.
Maybe your asking for something different, but I figured that was what you were looking for.

Re: Types, Type Hinting, Casting

Posted: Wed Dec 30, 2009 12:04 pm
by daedalus__
i don't think you can hint primitive types. and i think that there is a distinct type for binary strings in php6.

and i dont use php doc either so can't help you there sorry P:

Re: Types, Type Hinting, Casting

Posted: Thu Dec 31, 2009 6:49 am
by kaisellgren
The manual says nothing about type hint support (except for the obvious array + object that has been around for quite some time).

I found one interesting post by Ilia http://ilia.ws/archives/207-Type-Hintin ... usion.html

So it seems no one knows the answer.

I'm still interested in hearing your PHPDoc preferences though.