Skip to content
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

Return type error in Phalcon\Application\AbstractApplication #14293

Closed
Laxilef opened this issue Aug 8, 2019 · 6 comments
Closed

Return type error in Phalcon\Application\AbstractApplication #14293

Laxilef opened this issue Aug 8, 2019 · 6 comments

Comments

@Laxilef
Copy link

Laxilef commented Aug 8, 2019

All methods of the class Phalcon\Application\AbstractApplication return the type Application instead of AbstractApplication / self / ApplicationInterface:

namespace Phalcon\Application;

use Phalcon\Application\Exception;
use Phalcon\Di\DiInterface;
use Phalcon\Di\Injectable;
use Phalcon\Events\EventsAwareInterface;
use Phalcon\Events\ManagerInterface;

/**
 * Base class for Phalcon\Cli\Console and Phalcon\Mvc\Application.
 */
abstract class AbstractApplication extends Injectable implements EventsAwareInterface {

...
...
...

public function registerModules(array modules, bool merge = false) -> <Application>

Example

Errors:
Fatal error: Declaration of App\Library\Mvc\Application::registerModules(array $modules, bool $merge = false): App\Library\Mvc\Application must be compatible with Phalcon\Application\AbstractApplication::registerModules(array $modules, bool $merge = NULL): Phalcon\Application\Application
Fatal error: Uncaught TypeError: Return value of App\Library\Mvc\Application::registerModules() must be an instance of Phalcon\Application\Application, instance of App\Library\Mvc\Application returned

Details

  • Phalcon version: 4.0.0-beta.1
  • PHP Version: PHP 7.0.33-0+deb9u3 (cli) (built: Mar 8 2019 10:01:24) ( NTS )
  • Operating System: debian 9
  • Installation type: Compiling from source
  • Zephir version (if any): Version 0.12.0-c893389
@Jeckerson
Copy link
Member

Hi

Can you show your code where it happens?

@Laxilef
Copy link
Author

Laxilef commented Aug 8, 2019

@Jeckerson, of course

<?php
namespace App\Library\Mvc;
use Phalcon\Mvc\Application as MvcApplication;

class Application extends MvcApplication {
	/**
	 * Register an array of modules present in the application
	 * @param array $modules
	 * @param boolean $merge
	 * @return $this
	 */
	public function registerModules(array $modules, bool $merge = false): Application  {
		$this->eventsManager->fire('application:beforeRegisterModules', $this);
		parent::registerModules($modules, $merge);
		$this->eventsManager->fire('application:afterRegisterModules', $this);

		return $this;
	}
}

p.s. I experimented with these return types:

  • Application/this/self
  • Phalcon\Application\AbstractApplication
  • Phalcon\Application\Application (but this class does not exist. But php asks so)

p.s.s. Also i tried:

$ret = parent::registerModules($modules, $merge);
...
...
...
return $ret;

@Jeckerson
Copy link
Member

Add use of Phalcon\Application\Application

For example:

use Phalcon\Application\Application as PhalconApplication;

public function registerModules(array $modules, bool $merge = false): PhalconApplication

@Laxilef
Copy link
Author

Laxilef commented Aug 13, 2019

@Jeckerson Uncaught TypeError: Return value of App\Library\Mvc\Application::registerModules() must be an instance of Phalcon\Application\Application, instance of App\Library\Mvc\Application returned

@niden niden added 4.0 labels Aug 13, 2019
@niden
Copy link
Member

niden commented Aug 13, 2019

Thanks @Laxilef We will sort this out.

@sergeyklay
Copy link
Contributor

Fixed in the 4.0.x branch. Feel free to open a new issue if the problem appears again. Thank you for contributing.

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

No branches or pull requests

4 participants