Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

array keyword before function parameters in PHP

Tags:

php

I saw a function declared like this:

public static function factory($file=null, array $data=null, $auto_encode=null)

If you want to see the real class, please go to this view.php class from a fork of fuelphp parser package in github.

My question is, what does array keyword means in array $data = null?

like image 751
ayublin Avatar asked Feb 24 '23 00:02

ayublin


1 Answers

This is an example of PHP5's type hinting. The parameter $data is supposed to be an array. It is possible to hint method parameters as either object or array types. If it is an object, you can specify the name of the class as the hint keyword.

like image 110
Michael Berkowski Avatar answered Feb 25 '23 14:02

Michael Berkowski