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

Ticket #1091 (confirmed bug)

Opened 4 years ago

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

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

comment:1 Changed 4 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....

comment:2 Changed 4 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 2 years ago by laurentj

  • Status changed from new to confirmed

comment:4 Changed 2 years ago by laurentj

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

comment:5 Changed 2 years ago by laurentj

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