Skip to content
Advertisement

Tag: type-hinting

Laravel – Middleware custom typed Request parameter

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

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

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

Advertisement