Page 1 sur 1

Constant which undefine itself...

Posté : 24 oct. 2006, 16:06
par Littlebusy
Hi,

I have an unbelievable problem... In the following php code :

Code : Tout sélectionner

include_once($strHomePath."sitedef.php"); echo defined("PATH_CLASS") ? "True<br/>" : "False<br/>"; echo PATH_CLASS."<br/>"; include_once(PATH_LOGICS."common.logics.php");
In the first file included i define the constant PATH_CLASS.
The output is :
In the file PATH_LOGICS."common.logics.php" the first lines are

Code : Tout sélectionner

echo defined("PATH_CLASS") ? "True<br/>" : "False<br/>"; echo PATH_CLASS."<br/>";
and the output is :
False
PATH_CLASS
!!!

Does Somebody know where can it come from ?

Thanks.

Posté : 24 oct. 2006, 16:12
par sadeq
Where is defined PATH_LOGICS and what is it's value ?

Traduction en français:
J'ai dit: Où est déclarée la constante PATH_LOGICS et quelle est sa valeur?

littlebusy qui a dit :
Salut,

J'ai un problème incroyable... dans le code Php suivant :
Code:
include_once($strHomePath."sitedef.php");
echo defined("PATH_CLASS") ? "True<br/>" : "False<br/>";
echo PATH_CLASS."<br/>";
include_once(PATH_LOGICS."common.logics.php");


J'ai défini la constante PATH_CLASS dans le premier fichier inclus.

ça m'affiche ceci:
True
http://localhost/class

Les premières lignes de code du fichier PATH_LOGICS."common.logics.php" sont:
echo defined("PATH_CLASS") ? "True<br/>" : "False<br/>";
echo PATH_CLASS."<br/>";

et ça affiche ceci:
False
PATH_CLASS


!!!

Est-ce que quelqun sait d'où vient le problème?

Merci.

Posté : 24 oct. 2006, 16:15
par Invité
The constan is defined in the file '$strHomePath."sitedef.php"'
and its value is 'http://localhost/class'

Posté : 24 oct. 2006, 16:19
par sadeq
Because if it's a remote path begining with http:// like the PATH_CLASS,
the script "common.logics.php" included can't use the local constant PATH_CLASS unless it's defined inside or passed as a posted parameter.

Remote files included in a script are executed out of the main local workspace. Only result is passed to main after it's done.

Traduction en français:
J'ai dit: Comme l'url de l'include commence par un "http://" comme l'url de PATH_CLASS d'ailleurs, le script "common.logics.php" inclus ne peut pas utiliser la constante PATH_CLASS car elle n'est pas déclarée dans son contexte ou passée comme paramètre.
Les fichiers php distants inclus dans un script sont exécutés hors de son espace de travail. Seuls les résultats sont retournés après exécution.

littlebusy qui a dit :
Cette constante est déclarée dans le fichier '$strHomePath."sitedef.php"'
et sa valeur est 'http://localhost/class'

Posté : 24 oct. 2006, 16:27
par Invité
Excuse me i didn't see 'LOGICS' i read too fast !

so PATH_LOGICS is 'http://localhost/logics'

So even if the server pointed is the same during all the script processing, php considers 'http' as a remote server ?

Posté : 24 oct. 2006, 16:49
par sadeq
Yes, all "http://" protocol access are processed as a remote call even if it's a self host http call.
A new thread is constructed for the new call on the same server, but the workspaces are different.

The problem with you is that your main script can't view the classes definitions included by an http request unless it's returned to the main as a simple text. The main have to evaluate returned definition to construct the classes.

So, you can't share variables, constants and classes definitions between the main and remote includes (unless passing them as parameters)

Traduction en français:
J'ai dit: Exactement, tout accès via le protocole "http://" est un appel distant même si un serveur appelle lui même en utilisant http.
Un nouveau processus est créé normalement pour tout appel http du même serveur, les espaces de travail des processus sont alors différents.
Ton problème se traduit par le fait que ton script principal ne peut même pas utiliser les définition de classes incluses par http. sauf si le script inclus transmet ces définitions sous forme de texte que le script principal doit évaluer (exécuter en tant que code php) pour construire les classes.

Donc, tu ne peux pas partager des variables, des constantes et des classes entre le script principal et ceux inclus à distance (sauf bien sur en les passant comme paramètres).


littlebusy qui a dit :
Ô pardon, je n'ai pas vu 'LOGICS' j'ai lu rapidement !

la valeur de PATH_LOGICS est 'http://localhost/logics'

Si j'ai bien compris, Php considère 'http' comme un appel à un serveur distant même si le serveur ciblé est le même que celui qui exécute le script. N'est-ce pas?

Posté : 25 oct. 2006, 11:31
par Invité
OK, thank you very much for your help. I can't tag the subject resolved but it is.

Posté : 25 oct. 2006, 12:58
par Cyrano
I can't tag the subject resolved but it is.
It's done.
By the way, this forum is usualy in french. Some members can use english, but next time, try to use our language. Speak french or speak PHP is not so different.

Have a nice day.