Strict types in Zend Framework and in PHP

As you may know you can add strict types for a function parameters in PHP i.e.

public function func1(string $test)
{}

and this may be some simple function in some Zend Framework standard model! Now the problem comes with the instance of this function. If you call it like this:

func1('foo bar');

in a ZF controller, you simply will get an error.

It is strange …

isn’t it! But in PHP you can use strict types only for an array, which is built in type. In other words if some object implements the __toString() method than you can use string strict type.

Related posts:

  1. Download Files with Zend Framework
  2. Detecting POST Requests in Zend Framework
  3. Models in Zend Framework – Initialize All Methods with init()
This entry was posted in micro tutorial, PHP, zend framework and tagged , , . Bookmark the permalink.

2 Responses to Strict types in Zend Framework and in PHP

  1. Actually, the only types you can use for type hinting in PHP are “array”, “object”, and any interface or class name — and that’s it. You cannot hint on any of the scalar types (string, bool, int, float, etc.).

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">