jQuery mobile and PHP define variable


I'm really new with jQuery mobile but am loving working with it! I've come across a few problems regarding caching that I'm struggling with.

I have a php file with the followingdefine in it:

define('HEADING_TITLE', 'Page 1');

That file is loaded on page 1 of the website. When I echo HEADING_TITLE, I see 'Page 1'.

Page 2 requires a different php file that overrides HEADING_TITLE as follows:

define('HEADING_TITLE', 'Page 2');

When I echo HEADING_TITLE, I still see 'Page 1'. I know the page 2 define is being processed because if I add the linedie(HEADING_TITLE); immediately after the define, the script does indeed die but still shows me 'Page 1'!

How do I get jQuery mobile to allow me to overwrite the HEADING_TITLE variable? Or will I need to go about this another way? Creating different define variables like PAGE1_HEADING_TITLE and PAGE2_HEADING_TITLE is no problem, but if there's a better way I'd love to know it.




Short answer is you can't override a define, they are called constants for a reason. Long answer is, you can in the runtime, but it's hacky and a bad idea.

If you choose to over-ride a constant in the runtime, do it like so:

runkit_constant_redefine("HEADING_TITLE", 'Page 2');

People are also looking for solutions to the problem: php - monolog with different levels and environments


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.