Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all! We have been experiencing an issue on site where threads have been missing the latest postings. The platform host Vanilla are working on this issue. A workaround that has been used by some is to navigate back from 1 to 10+ pages to re-sync the thread and this will then show the latest posts. Thanks, Mike.
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

PHP constant problem

  • 13-03-2013 4:46pm
    #1
    Registered Users, Registered Users 2 Posts: 160 ✭✭


    Hi there

    I'm working on a class in a PHP web app which defines a number of class constants. It turns out that we want these constants to be initialised to different values and not modified again, depending on a certain condition being true.

    I realise class constants can only be assigned values when they are declared, and that a variable is more appropriate for what we want, but these constants are referred to in hundreds of places, and I want to minimise the code change elsewhere in the app.

    I've tried creating two new classes, each containing a set of consts with names common to both files, but assigning them different values. Depending on a particular conditional statement being true or false, I then include one of the class files and assigning the original class constants I mentioned the values in the included PHP file.

    However, this seems to work in some places and not in others. In some files that include the class with the constants defined, they successfully reference the constants and they contain the correct value.

    In other files though, though, I simply get an error :" Undefined class constant 'Classname::constantname.' The files that experience the error are in a different directory, but the include paths are accurate, it's just it doesn't seem to know anything about the values.

    Any ideas? Cheers


Comments

  • Registered Users, Registered Users 2 Posts: 6,465 ✭✭✭MOH


    From a long-term maintainability point of view, you might be better biting the bullet and changing them to variables. Having "constants" that effectively aren't is likely to end up confusing anyone who ends up maintaining the code later.

    As it stands, are you 100% sure the class file is being included? Can you create an instance of the class OK?


Advertisement