is not used any more and exists only for history. Post new tickets on the Github account. n'est plus utilisée, et existe uniquement pour son historique. Postez les nouveaux tickets sur le compte github.

Opened 11 years ago

Last modified 10 years ago

#1091 confirmed bug

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: Blocked By:
Blocking: Documentation needed: no
Hosting Provider: Php version:


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 (5)

comment:1 Changed 11 years ago by laurentj

  • Component changed from jelix to jelix:core
  • Milestone set to Jelix 2.0
  • Owner set to laurentj

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....

comment:2 Changed 11 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

comment:3 Changed 10 years ago by laurentj

  • Status changed from new to confirmed

comment:4 Changed 10 years ago by laurentj

  • Owner changed from laurentj to none
  • Status changed from confirmed to assigned

comment:5 Changed 10 years ago by laurentj

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