Skip to content

APPPATH, SYSPATH and similar constants. Rename? #2

Closed

Description

@ivantcholakov

Sorry for barking so early. :-)

Sample APPPATH, SYSPATH usage:
https://github.com/lonnieezell/CodeIgniter4/blob/develop/application/config/autoload.php#L33

Is it possible these constants to be renamed or name-spaced? Maybe in the distant future I'll make an attempt for compatibility layer about CI3. A name collision between certain CI3 and CI4 constants seems to me an obstacle for this goal.

Activity

  1. lonnieezell commented on Aug 28, 2015

    @lonnieezell
    Member

    Yeah, a bit early. See the readme :)

    I've given some thought to a compatibility layer (unofficially) before, too, and I'm not convinced that this needs to be different. And it seems like it might help in some ways to keep them the same, because if the structure is kept with application and system folders, then anytime you use those paths in your application, they still point to the same general area. If you're setting up multiple applications that share the system folder, then your old application folder could use the same constants and still be correct.

    I'm not 100% convinced this change is necessary, but it's definitely something to consider as we move forward.

  2. jim-parry commented on May 31, 2016

    @jim-parry
    Contributor

    Further thoughts on this? If a change is to happen, then now (before first milestone) would be the time to do it.
    For the record, I am not in favor of such a change -> the more familiar things we have, the easier I see it transitioning from CI3 to CI4 once ready.

  3. lonnieezell commented on May 31, 2016

    @lonnieezell
    Member

    I agree - not in favor of this one, in large part due to the familiarity aspect. While he does have a point for specific upgrade paths, I see upgrading from 3 to 4 as being a large enough of a project as to not necessarily be feasible. However, you could have both versions running side by side, and certain modules run on one version and another run on another version, the main tricky thing here would be handling routing, but should be possible.

  4. jim-parry commented on May 31, 2016

    @jim-parry
    Contributor

    I am not convinced that we should provide for CI3 and CI4 side-by-side (in the same app, I presume) ... that feels like way too big a can of worms. I don't recall any attempt to do that with CI2 -> CI3, it was one or the other IIRC.

    From what I am seeing, if the constants are extensively used in code (sounds like a good practice), then a conversion/migration guide, which referenced them, would be a better service than renaming the path constants.

  5. lonnieezell commented on May 31, 2016

    @lonnieezell
    Member

    OH, yeah, I wasn't saying that we go out of our way to allow to run side by side, but that's how any large migrations are likely to work - moving one part of the site at a time over. I've heard people on the forums talk about doing that between 2 and 3. The constants didn't provide any problems there, but the codebases were similar enough that it probably wouldn't have caused a problem.

  6. ivantcholakov commented on May 31, 2016

    @ivantcholakov
    Author

    A suggestion without thinking too much:
    FC_PATH
    SYS_PATH
    APP_PATH
    ... and the same rule for other that I might miss.

  7. sv3tli0 commented on May 31, 2016

    @sv3tli0
    Contributor

    I already suggested in other discussions that Path constants is OLD PHP practice and perhaps it must be replaced, either by path generator class or something like that. Specially with the new autoloader its even more comfortable to have some class to manage paths instead of some inline written paths using constants..

    By using constants at each place where you use them you have to always check if the required file exists and then or else..

  8. jim-parry commented on May 31, 2016

    @jim-parry
    Contributor

    Hmmm ... define CI4 constants for the path name (CI4_APP, CI4_FC, ...) and then have something like path(CI4_APP)?
    Not sure ... this feels off.

    Or CodeIgniter\Path class with app, fc, view, etc methods?

  9. lonnieezell commented on May 31, 2016

    @lonnieezell
    Member

    I see no problem with global constants for these type of things, personally. I know people like to have classes for everything and shy away from any "old school" PHP, but they all have their place. Besides, a class takes more CPU and memory to use than a constant. And having a new class just to hold static values is the type of thing I was always told was bad use of OOP. These are values that will never change throughout the request so a constant is the language feature intended to handle those. While we could add it to the Codeigniter class, and I'd be semi-ok with that, the use is even more complex for developers because it's no longer

    if (file_exists(APPPATH.'cache/whatever'))
    

    It's getting a reference to the CodeIgniter class and then calling a method on that class to return a value that will never change. Seems overkill to me. Personally, the language features are still there and it's not bad form to use standalone methods, or global constants, etc, as long as they're used with care. Spaghetti code can be created in thoroughly OOP code (though I understand the term for that is lasagna code), so it's not that the feature is used, it's how it's used.

    And we are trying to keep some of the flavor and feel of CI after all. :)

    I also don't see a need to "namespace" the constants. It might make sense if we didn't have 10+ years of history with the old ones. As far as I can think of for the upgrade process, you're only ever going to be in one version or the other during a single request, so I can't see the constants interfering with each other. And, if they did, the system would crash, telling the dev what to fix.

    While I'll go along with the majority on this, neither of these suggestions seem necessary or even like a great idea.

  10. jim-parry commented on May 31, 2016

    @jim-parry
    Contributor

    I vote that we stick with the existing constants (their names). Migrating is going to be enough fun without changing them.

  11. jim-parry commented on Jun 5, 2016

    @jim-parry
    Contributor

    Lets keep it as implemented.

  12. added a commit that references this issue on Oct 24, 2017
  13. added a commit that references this issue on Jul 27, 2018
  14. added a commit that references this issue on Oct 29, 2018
  15. added a commit that references this issue on Feb 7, 2019
  16. added a commit that references this issue on Apr 1, 2019
  17. added a commit that references this issue on Nov 14, 2019
  18. added a commit that references this issue on Dec 10, 2019
  19. added a commit that references this issue on Aug 21, 2020
  20. added a commit that references this issue on Sep 24, 2020
  21. added a commit that references this issue on Jan 17, 2021
  22. added a commit that references this issue on Dec 11, 2021
  23. added a commit that references this issue on Oct 8, 2022
  24. added a commit that references this issue on Jan 21, 2023
  25. added a commit that references this issue on Apr 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions