Continuing from the thread of last February (2008) started here:
http://tinyurl.com/6pvbgk (Google Groups link)
Setup: I have a big tree of "if" statements (imagine the PHP code
version of a choose-your-own-adventure story) and I want to be able to
tell which end-branch I've reached. Right now, l have all the end-
branches numbered with integers, and the integer of the end branch is
returned.
Problem: If I insert a new end-branch somewhere in the middle, I have
to laboriously re-number all the end branches that come after it. As
the tree gets larger and larger, this becomes more and more of a
hassle.
The application in question is at
In my original post I wondered if PHP had any functionality that would
allow me to have the engine auto-insert the numbering for me on a pass
of the script that would occur prior to execution. That way, I could
make the script just have some sort of ++ deal at each end branch,
rather than assigning the numbers in the script by hard-coding them
in.
The replies indicated that PHP had no such pre-parser or pre-processor
functionality. A couple of replies suggested using the __LINE__
directive but when I tried to implement that, I realized it would not
work (for reasons that I now don't clearly remember).
Returning to the problem months later, I now learn about the PHP
tokenizer. Example 2 at the tutorial posted here looks promising:
However, examining how the example works, it seems like it is only
capable of "switch"-like functionality and I am left unclear as to
whether or how incrementing would be performed to leave each end
branch of a big if tree with a unique integer.
I have also heard about something called "Smarty" but smarty.net
appears to be experiencing problems at the moment.
Thoughts appreciated.
Cheers,
Robert K S
http://tinyurl.com/6pvbgk (Google Groups link)
Setup: I have a big tree of "if" statements (imagine the PHP code
version of a choose-your-own-adventure story) and I want to be able to
tell which end-branch I've reached. Right now, l have all the end-
branches numbered with integers, and the integer of the end branch is
returned.
Problem: If I insert a new end-branch somewhere in the middle, I have
to laboriously re-number all the end branches that come after it. As
the tree gets larger and larger, this becomes more and more of a
hassle.
The application in question is at
In my original post I wondered if PHP had any functionality that would
allow me to have the engine auto-insert the numbering for me on a pass
of the script that would occur prior to execution. That way, I could
make the script just have some sort of ++ deal at each end branch,
rather than assigning the numbers in the script by hard-coding them
in.
The replies indicated that PHP had no such pre-parser or pre-processor
functionality. A couple of replies suggested using the __LINE__
directive but when I tried to implement that, I realized it would not
work (for reasons that I now don't clearly remember).
Returning to the problem months later, I now learn about the PHP
tokenizer. Example 2 at the tutorial posted here looks promising:
However, examining how the example works, it seems like it is only
capable of "switch"-like functionality and I am left unclear as to
whether or how incrementing would be performed to leave each end
branch of a big if tree with a unique integer.
I have also heard about something called "Smarty" but smarty.net
appears to be experiencing problems at the moment.
Thoughts appreciated.
Cheers,
Robert K S
Comment