Bug #58953

When an import is missing, no error is shown

Added by Aimo Künkel about 1 year ago. Updated about 1 year ago.

Status:Closed Start date:2014-05-20
Priority:Could have Due date:
Assigned To:Bastian Waidelich % Done:

0%

Category:-
Target version:-
PHP Version: Complexity:
Has patch:No Affected Flow version:Git master

Description

When you use a type hint in an action without namespace and you forgot to import that class, the response will be a blank page witout error message, log or exception.
This can be hard to debug and it would be really nice if something is shown here.

Example class to test with:

<?php
namespace Vendor\Package\Backend\Controller;

use TYPO3\Flow\Annotations as Flow;

class TestController ... {

    /**
     * results in blank page
     * 
     * @param  Vendor\Package\Domain\Model\Object $object the object to show
     * @return void
     */
    public function testAction(Object $object) {
        $this->view->assign('object', $object);
    }

}

The "Object" here used as parameter is never imported, that's why it breaks.

History

#1 Updated by Aimo Künkel about 1 year ago

I put this up because my (and propably any other) php linter doesn't recognize this as an error (since Object is just searced in the current NS), so i guess quite some other IDEs won't show it as an error as well and when copying an action from one Controller to another you can search forever to find this ;)

#2 Updated by Bastian Waidelich about 1 year ago

  • Category deleted (Error)
  • Status changed from New to Needs Feedback
  • Assigned To set to Bastian Waidelich

Hi Aimo,

I was surprised and tried to reproduce the problem - without success..

In Development Context I get an exception:

Uncaught Exception in Flow
#1: Catchable Fatal Error: Argument 1 passed to Vendor\Package\Backend\Controller\TestController_Original::testAction() must be an instance of Vendor\Package\Backend\Controller\Object, instance of Vendor\Package\Domain\Model\Object given in [...]/Data/Temporary/Development/Cache/Code/Flow_Object_Classes/Vendor_Package_Backend_Controller_TestController.php line [...]

In Production Context the exception message is hidden for security reasons (it only shows "500 server error, ...") - But the same exception is logged.

Can you add some more details on how to reproduce this please?

BTW: The @param annotation in your example misses the leading backslash

#3 Updated by Aimo Künkel about 1 year ago

Thanks for your update Bastian,

on my machine there's a blank result, on my colleague's machine it shows

Fatal error: Cannot redeclare class Vendor\Package\Controller\TestController in .../Packages/Application/Vendor.Package/Classes/Vendor/Package/Controller/TestController.php on line 196

We're both in dev context and tried the same code.
Does it maybe depend on the php error settings?

And thanks for your annotation hint: why didn't i never realize this is a problem without the leading Backslash? Does flow behave the same?

#4 Updated by Bastian Waidelich about 1 year ago

Aimo Künkel wrote:

on my machine there's a blank result, on my colleague's machine it shows

Fatal error: Cannot redeclare class Vendor\Package\Controller\TestController in .../Packages/Application/Vendor.Package/Classes/Vendor/Package/Controller/TestController.php on line 196

We're both in dev context and tried the same code.
Does it maybe depend on the php error settings?

Yes, most probably. It's very important that you set up your development environment correctly in order not to get unpleasant surprises like this one.

And thanks for your annotation hint: why didn't i never realize this is a problem without the leading Backslash? Does flow behave the same?

Depends on what tools you use, but a good IDE like PhpStorm highlights these very prominently. Also the unresolvable "Object" type hint

#5 Updated by Aimo Künkel about 1 year ago

Thanks for the info

  1. Is there a recommendation for "set up correctly"?
  2. do simple type also need a leading Backslash?
  3. and still: does flow bahave differently?

And please close the issue :)

#6 Updated by Bastian Waidelich about 1 year ago

  • Status changed from Needs Feedback to Closed

Aimo Künkel wrote:

  1. Is there a recommendation for "set up correctly"?

You don't really need anything special for Flow/Neos to run (except for the "date.timezone" ini-setting that is required).

Some of the general things to consider for setting up a proper PHP development environment include:
  • correct error configuration (display/log errors, appropriate error_reporting level)
  • enough memory for the php process
  • read/write access to affected folders
  • ...

Usually PHP comes with prepared php.ini files for development and production use.
For Flow specific requirements see http://docs.typo3.org/flow/TYPO3FlowDocumentation/TheDefinitiveGuide/PartII/Index.html

  1. do simple type also need a leading Backslash?

If you omit the namespace, PHP falls back to the "global space" (see http://de3.php.net/manual/en/language.namespaces.global.php). So, no, you don't need them. Otherwise you'd had to write "\echo" instead of just "echo" for example..
You can of course do that but according to our coding guidelines we omit the one backslash for types and functions of the global space.

And please close the issue :)

Done, thx

Also available in: Atom PDF