سؤال

I'd like my functions to expect strings/integers or throw a fit, like:

warning: preg_match() expects parameter 2 to be string

However for this function

public function setImage($target, $source_path, integer $width, integer $height){...

I get:

Argument 4 passed to My_Helper_Image::setImage() must be an instance of integer, integer given

But:

function(array $expectsArray)

works as I expect, how would I achieve the same effect as with integers and strings?

Big Update

PHP 7 now supports Scalar Type Hinting

function increment(int $number) {
     return $number++;
}

لا يوجد حل صحيح

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top