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

Comments

@Laxilef
Copy link

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

This comment has been minimized.

Copy link
Member

commented Aug 8, 2019

Hi

Can you show your code where it happens?

@Laxilef

This comment has been minimized.

Copy link
Author

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

This comment has been minimized.

Copy link
Member

commented Aug 11, 2019

Add use of Phalcon\Application\Application

For example:

use Phalcon\Application\Application as PhalconApplication;

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

This comment has been minimized.

Copy link
Author

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 this to To do in 4.0 Release via automation Aug 13, 2019

@niden

This comment has been minimized.

Copy link
Member

commented Aug 13, 2019

Thanks @Laxilef We will sort this out.

@niden niden moved this from To do to In progress in 4.0 Release Aug 14, 2019

niden added a commit to niden/cphalcon that referenced this issue Aug 14, 2019
niden added a commit to niden/cphalcon that referenced this issue Aug 14, 2019
niden added a commit to niden/cphalcon that referenced this issue Aug 14, 2019
@niden niden referenced this issue Aug 14, 2019
3 of 5 tasks complete
@sergeyklay

This comment has been minimized.

Copy link
Member

commented Aug 14, 2019

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

@sergeyklay sergeyklay closed this Aug 14, 2019

4.0 Release automation moved this from In progress to Done Aug 14, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
4 participants
You can’t perform that action at this time.