Ticket #1091 (confirmed bug)

Opened 3 years ago

Last modified 17 months ago

PHP crashes on particuliar cases when having 2 controllers with same name (in 2 modules)

Reported by: bricet Owned by:
Priority: normal Milestone: Jelix 2.0.0
Component: jelix:core Version: trunk
Severity: normal Keywords:
Cc: Php version:
Hosting Provider: Blocked By:
Documentation needed: no Blocking:

Description

I don't perceive how general this problem is. I guess it may appear with plugin coordinators. May be it is even more general.

Here is a simple way to reproduce :

  1. use jAuth
  2. in module modA, create a controller called 'myCont'
  3. in module modB, create a controller called 'myCont'
  4. create an action in modA (e.g. actA) and modB (e.g. actB)
  5. set actA as needing authentication using 'auth.required'=>true in modA~myCont's pluginParams
  6. set on_error_action = "modB~myCont:actB" in auth.coord.ini.php
  7. try accessing modA~myCont:actA in your browser

PHP crashes telling :

Fatal error: Cannot redeclare class myContCtrl in .../modules/modB/controllers/myCont.classic.php on line X

(BTW, using apc is even worse because nothing is displayed. You thus have to look to apache's error.log).

So this problem is due to the fact that 2 controllers have the same name.

In this particular case, this seems to be due to AuthCoordPlugin? which redefines the action selector. I guess this is due to a design problem, so I have no clue to tell how is the best way to solve that ... instead of renamming one of the controllers, which I am going to do right now as a quick personnal fix ...

Change History

Changed 3 years ago by laurentj

  • owner set to laurentj
  • component changed from jelix to jelix:core
  • milestone set to Jelix 2.0

You can think that it is a design problem. But I don't how to fix it properly. PHP doesn't authorize to have two classes with the same name. This is a fact, and we cannot force it.

So the only one solution is to use different names, for exemple by including the module name in the name of the class.

In Jelix 2, we will support namespaces (PHP 5.3 only so...) and each class of a module should be in a namespace dedicated to the module. So we won't have this issue any more.

But for the moment, I think there isn't any solution, except the solution to rename controllers.

If you have other ideas....

Changed 3 years ago by geekbay

Maybe in such a case, what you can do is to not use the 'auth.required'=>true but in the controller

if(!jAuth::isConnected) {
  $rep = $this->getResponse('redirect');
  $rep->action = modB~myCont:actB;
  return $rep;
}

and then you don't need to change controller's name

Changed 17 months ago by laurentj

  • status changed from new to confirmed

Changed 17 months ago by laurentj

  • owner changed from laurentj to none
  • status changed from confirmed to assigned

Changed 17 months ago by laurentj

  • owner none deleted
  • status changed from assigned to confirmed
Note: See TracTickets for help on using tickets.