Marcus Bointon wrote:
On 28 Jul 2005, at 12:07, André Medeiros wrote:
On Thu, 2005-07-28 at 11:08 +0200, marc serra wrote:
Hi, i want to know if it is possible to create a function and declare
that one of its arguments is array type.
In fact i want to do something like this
function test(String $litteral, array $foo){
unless String is a class you defined that won't work at all. basic data types
cannot be hinted (e.g. bool, int, string, float)
There is no way to do that. What you _CAN_ do, to ensure you're getting
an array is:
There IS a way to do exactly this. It's called type hinting and it's a
PHP 5 feature:
for a split second I was about to say a word start with 'bull', but Marcus
is more or less correct - typehints for classes has existed since the beginning
of php5, the ability to typehint arrays is aparently being included in php5.1
(still in beta).
thanks Marcus for the heads up. :-)
=================
now don't get me started on the fact that 'they' pulled the plug on being able
to do they following - I feel the breath of some purist overlord breathing down
my neck:
class Test { /* ... */ }
function foo(Test $t = null) { /* ... */ }
(the above worked in the first few betas of php5.0)
if a php 'God' reads this (and at least one of you is kind enough to grace us with
his presence on this list) - please reconsider allowing typehints with defaults of
NULL (only NULL and nothing else is more than enough for me!).
http://www.php.net/manual/en/language.oop5.typehinting.php
Marcus
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php