Skip to content

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

Closed
@nissim94

Description

@nissim94

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');
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions