PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > Is there any sort of preprocessor functionality in PHP4?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Is there any sort of preprocessor functionality in PHP4?

Réponse
 
LinkBack Outils de la discussion
Vieux 13/02/2008, 22h58   #1
Robert K S
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Is there any sort of preprocessor functionality in PHP4?

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, 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.

This has me wondering if PHP has 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.

Alternatively, is there some other way to accomplish the same thing?

Thanks!

Robert K S
  Réponse avec citation
Vieux 13/02/2008, 23h20   #2
Michael Fesser
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Is there any sort of preprocessor functionality in PHP4?

..oO(Robert K S)

>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, 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.
>
>This has me wondering if PHP has 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.
>
>Alternatively, is there some other way to accomplish the same thing?


It would to post some more details about what you're trying to
achieve.

Micha
  Réponse avec citation
Vieux 14/02/2008, 02h36   #3
axlq
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Is there any sort of preprocessor functionality in PHP4?

In article <5d2b0983-ec15-4724-8624-3cc2c1bc0d92@i7g2000prf.googlegroups.com>,
Robert K S <robertks@gmail.com> wrote:
>Problem: If I insert a new end-branch, I have to laboriously re-number
>all the end branches that come after it.


Why? If all you need is a unique ID for each branch, what does it
matter what order they're in?

-A
  Réponse avec citation
Vieux 14/02/2008, 04h33   #4
Robert K S
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Is there any sort of preprocessor functionality in PHP4?

Thanks for the replies, Michael and axlq--

Michael: If you want to see the end result, check out
http://www.j-archive.com/wageringcalculator.php

Type three numbers in the fields and hit submit.

The number in parentheses at returned with each result is the branch
end ID.

axlq: Fair point, it doesn't matter what order they're in. What's the
best way to generate a unique ID for each end of the branch, such that
no ID can be repeated and the IDs are always consistent from execution
to execution?

All the best,
Robert K S
  Réponse avec citation
Vieux 14/02/2008, 09h12   #5
Rob
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Is there any sort of preprocessor functionality in PHP4?

On Feb 14, 4:33am, Robert K S <rober...@gmail.com> wrote:
> Thanks for the replies, Michael and axlq--
>
> Michael: If you want to see the end result, check outhttp://www.j-archive.com/wageringcalculator.php
>
> Type three numbers in the fields and hit submit.
>
> The number in parentheses at returned with each result is the branch
> end ID.
>
> axlq: Fair point, it doesn't matter what order they're in. What's the
> best way to generate a unique ID for each end of the branch, such that
> no ID can be repeated and the IDs are always consistent from execution
> to execution?
>
> All the best,
> Robert K S


Not sure if this really what you want, but what about using
array_unshift() to add an entry to the start of an array. That would
push all of the other entries down by one?

Rob.
  Réponse avec citation
Vieux 14/02/2008, 12h40   #6
C. (http://symcbean.blogspot.com/)
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Is there any sort of preprocessor functionality in PHP4?

On 13 Feb, 22:58, Robert K S <rober...@gmail.com> wrote:
> 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, 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.
>
> This has me wondering if PHP has 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.
>
> Alternatively, is there some other way to accomplish the same thing?
>
> Thanks!
>
> Robert K S


You're trying to polish a turd here.

If you really have so many 'if' conditions that you need to keep track
of them with arbitary data structures then you've gone the wrong way
about solving the problem.

The right way to solve the problem would be to push the branching
logic into a data structure. Go read up on expert systems and
heuristics.

C.
  Réponse avec citation
Vieux 14/02/2008, 17h43   #7
Robert K S
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Is there any sort of preprocessor functionality in PHP4?

On Feb 14, 7:40am, "C. (http://symcbean.blogspot.com/)"
<colin.mckin...@gmail.com> wrote:
> On 13 Feb, 22:58, Robert K S <rober...@gmail.com> wrote:
> > 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, 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.

>
> > This has me wondering if PHP has 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.

>
> > Alternatively, is there some other way to accomplish the same thing?

>
> > Thanks!

>
> > Robert K S


Thanks for the advice, Colin. Have you checked out the application?
Writing an inference engine in PHP would be overkill. If there was an
open source solution that I could tinker with, I might look into it.
In the meantime, it's much more cost-effective on my part to keep
polishing the turd. (I'm also not convinced the collection of
questions in the knowledgebase would be any less ungainly than the if-
tree of value comparison conditionals that I already have in place.)

Rob, thanks also for your reply. I hope I'm understanding you're
suggestion correctly, but if I'm not, please set me straight.
array_unshift is a runtime function and so it would only operate on
branches of the if-tree that are reached during execution. I was
hoping that there was some capability in PHP that worked the script
over before runtime.

Robert
  Réponse avec citation
Vieux 15/02/2008, 03h03   #8
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Is there any sort of preprocessor functionality in PHP4?

Robert K S wrote:
> On Feb 14, 7:40 am, "C. (http://symcbean.blogspot.com/)"
> <colin.mckin...@gmail.com> wrote:
>> On 13 Feb, 22:58, Robert K S <rober...@gmail.com> wrote:
>>> 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, 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.
>>> This has me wondering if PHP has 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.
>>> Alternatively, is there some other way to accomplish the same thing?
>>> Thanks!
>>> Robert K S

>
> Thanks for the advice, Colin. Have you checked out the application?
> Writing an inference engine in PHP would be overkill. If there was an
> open source solution that I could tinker with, I might look into it.
> In the meantime, it's much more cost-effective on my part to keep
> polishing the turd. (I'm also not convinced the collection of
> questions in the knowledgebase would be any less ungainly than the if-
> tree of value comparison conditionals that I already have in place.)
>
> Rob, thanks also for your reply. I hope I'm understanding you're
> suggestion correctly, but if I'm not, please set me straight.
> array_unshift is a runtime function and so it would only operate on
> branches of the if-tree that are reached during execution. I was
> hoping that there was some capability in PHP that worked the script
> over before runtime.
>
> Robert
>


Robert,

No, PHP Has no preprocessor.

Of course, you could always use the __LINE__ directive to give the
current line number, if all you need to do is relate it back to a
specific statement.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 19h18.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,18450 seconds with 16 queries