I want to use VacancyListRequest to pass through middleware parameters and use its rules to validate them before controller action. I know that middleware acts Pipeline pattern, but does anybody know how to use any custom type except default IlluminateHttpRequest? Middleware Controller Error AppHttpMiddlewareVacancyBeforeVacancyIndexRequestMiddleware::handle(): Argument #1 ($request) must be of type AppHttpRequestsVacancyVacancyListRequest, IlluminateHttpRequest given, Answer You are getting that error
Tag: type-hinting
With strict types enabled, array_map converts types anyways
I’ve came across a really interesting bug in PHP 7.0.11 where declare(strict_types=1); enabled does not make the array_map() nor array_walk() aware of strict types. I read somewhere that by enabling strict types PHP also uses strict types in core functions, but this is not the case. Look at this example code, it should throw TypeError exception: The var_dump result is:
Type hinting for the model objects of Eloquent ORM
I haven’t used laravel yet, but watching the tutorials on youtube left me with a question to type hinting, that is really important to me. Now I have read here Type Hinting Eloquent Models and here Eloquent ORM Code Hinting in PhpStorm but neither addresses the following problem: now lets say movie has a name, id, length, author all those
Type hinting with enumerations?
I’ve read here about enumarations and their “implementation” PHP and Enumerations point is, why use enums, when not for type hinting? but this implementation does not allow use for type hinting. Because the enum entries are all strings. is there a way I can say $a must be ‘foo’, ‘bar’ or ‘baz’ in PHP? I use phpstorm/intellij so if there
Type hinting in PHP 7 – array of objects
Maybe I missed something but is there any option to define that function should have argument or return for example array of User objects? Consider the following code: <?php class User { …
Nullable return types in PHP7
PHP 7 introduces return type declarations. Which means I can now indicate the return value is a certain class, interface, array, callable or one of the newly hintable scalar types, as is possible for …
PHP Type Hinting for a map (associative array) in NetBeans?
I’m trying to get advantage of NetBeans’ intelligent way of handling object types, so I’m hinting to every object’s type in comments. Problem is, I want to hint to an associative array of (string => …
PHP function parameter with callable hint… can it be NULL?
I would like to have a PHP function which accepts a parameter A, which I have given the type hint callable. Trouble is in some situations I would like to be able to pass NULL or something like that, …
Way to verify if variable is a valid GD image resource?
I have a class that accepts a GD image resource as one of its arguments. As far as I know, there is no way to type hint this since it is a resource and not an object. Is there a way to validate …
JetBrains WebIDE: PHP variable type hinting?
Is there a way to hint WebIDE that a variable has some type? I have to iterate an array of objects, and there’s no auto-completion available. This helps in ZendStudio: I know there’s a feature in JetBrains to declare an array of objects: But this works only with function’s return type. Answer /* @var ClassName $object */ is a non-valid