8000 Wrong variable types for route default parameters in PHP 7 · Issue #19869 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
8000

Wrong variable types for route default parameters in PHP 7 #19869

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nissim94 opened this issue Sep 6, 2016 · 1 comment
Closed

Wrong variable types for route default parameters in PHP 7 #19869

nissim94 opened this issue Sep 6, 2016 · 1 comment

Comments

@nissim94
Copy link
nissim94 commented Sep 6, 2016

Hi,

Type error: Argument 1 passed to OC\PlatformBundle\Controller\AdvertController::indexAction() must be of the type integer, string given

This error has been catched when you have defined default value to a parameter of a route, and type in the url banner /platform/ .

Normally /platform/ equals to /platform but with PHP 7 not.

when you use php5 there is no problem

see the code >>

routing.yml

oc_platform_home:
    path:      /platform/{page}
    defaults:
        _controller: OCPlatformBundle:Advert:index
        page: 1
    requirements:
        page: \d*

AdvertController.php

public function indexAction(int $page) : Response
    {
        if($page < 1){
            throw new NotFoundHttpException("Page $page inexistante");
        }

        return $this->render('OCPlatformBundle:Advert:index.html.twig');
    }
@nissim94 nissim94 changed the title [PHP 7] Symfony 3.1.4 code 500 => default parameter's value error in the route [PHP 7] Symfony 3.1.4 code 500 => default parameter's value error in the route #bug Sep 6, 2016
@javiereguiluz javiereguiluz changed the title [PHP 7] Symfony 3.1.4 code 500 => default parameter's value error in the route #bug Wrong variable types for route default parameters in PHP 7 Sep 6, 2016
@dunglas
Copy link
Member
dunglas commented Sep 6, 2016

In Symfony < 3.2, routing parameters are always of type string. #11394 introduced the ability to type routing parameters.
So you can use PHP 7's scalar type hints in your actions with Symfony 3.2+.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants
0