Type Hinting

You can specify what type of data expected in a function declaration. It could be Array type, int type, object type data.

<?php

class Book{

	public $price;
	public $authors;

	function getPrice(int $price){

		$this->price = $price;

	}

	function Authors(array $name){

		$this->authors = $name;

	}
}

$book = new Book;
$book->getPrice(100);
echo $book->price;

echo "<br/>";

$book->Authors(['Araf','Jahir']);
print_r($book->authors);

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s