static includes issue - bug?
5 posts
• Page 1 of 1
static includes issue - bug?
I'm trying to convert my PHP5 CLI script (which is quite complex and includes MANY classes) to an EXE. Since I'm running on the Console and not from the web, I need to statically load my includes. Here is the issue I'm having:
THIS WORKS:
include('data/project/config/constants.php');
constants.php is included during compilation.
THIS DOES NOT WORK:
$data_dir = 'data/project';
include($data_dir.'/config/constants.php');
constants.php is NOT included during compilation.
COMPILATION COMMAND:
phpc /config:bin\project.config /target:exe /lang:PHP5 cli/project.php
PROJECT.CONFIG PERTINENT LINES:
<set name="EnableStaticInclusions" value="true" scope="Any" />
<set name="StaticIncludePaths" value=".;..\..\xampp\xampp\php\pear" />
Thanks!
Jack
THIS WORKS:
include('data/project/config/constants.php');
constants.php is included during compilation.
THIS DOES NOT WORK:
$data_dir = 'data/project';
include($data_dir.'/config/constants.php');
constants.php is NOT included during compilation.
COMPILATION COMMAND:
phpc /config:bin\project.config /target:exe /lang:PHP5 cli/project.php
PROJECT.CONFIG PERTINENT LINES:
<set name="EnableStaticInclusions" value="true" scope="Any" />
<set name="StaticIncludePaths" value=".;..\..\xampp\xampp\php\pear" />
Thanks!
Jack
- jfburns@codeplex
- Posts: 15
- Joined: January 7th, 2012, 8:57 pm
RE: static includes issue - bug?
Hello Jack,
The problem with a statement like
include($data_dir.'/config/constants.php');
is that in general the compiler is unable to determine the actual file that is included. If you want your exe to contain the file without making changes to your source code, you have to do one of the following:
1) Append all potential included files to the phpc command line.
phpc /config:bin\project.config /target:exe /lang:PHP5 cli/project.php data/project/config/constants.php ...
2) Add an inclusion mapping to your project.config file. If the expression denoting the included file matches the given pattern, it is replaced by the given value (.NET regular expressions). The include will be consequently turned into a static include.
<set name="InclusionMappings" >
<add pattern="\$data_dir\s\.\s'(^'$+)'" value="data/project//$1" />
</set>
We are currently investigating an issue with 2) so I would recommend appending all potentially included sources to the command line.
The problem with a statement like
include($data_dir.'/config/constants.php');
is that in general the compiler is unable to determine the actual file that is included. If you want your exe to contain the file without making changes to your source code, you have to do one of the following:
1) Append all potential included files to the phpc command line.
phpc /config:bin\project.config /target:exe /lang:PHP5 cli/project.php data/project/config/constants.php ...
2) Add an inclusion mapping to your project.config file. If the expression denoting the included file matches the given pattern, it is replaced by the given value (.NET regular expressions). The include will be consequently turned into a static include.
<set name="InclusionMappings" >
<add pattern="\$data_dir\s\.\s'(^'$+)'" value="data/project//$1" />
</set>
We are currently investigating an issue with 2) so I would recommend appending all potentially included sources to the command line.
- Lada Prosek
- Posts: 47
- Joined: January 7th, 2012, 8:52 pm
RE: static includes issue - bug?
Confirming that there's a bug in static includes. Thanks for reporting this!
BTW, there should be start signs after \s in the pattern. There seems to be no way how to escape wiki markup here. Let's try this:
BTW, there should be start signs after \s in the pattern. There seems to be no way how to escape wiki markup here. Let's try this:
<compiler> <set name="EnableStaticInclusions" value="true" scope="Any" /> <set name="InclusionMappings" > <add pattern="\$data_dir\s*\.\s*'([^'$]+)'" value="data/project//$1" /> </set> </compiler>
- Lada Prosek
- Posts: 47
- Joined: January 7th, 2012, 8:52 pm
RE: static includes issue - bug?
Yup, the magic's in double curly open CODE double curly close :)
- Lada Prosek
- Posts: 47
- Joined: January 7th, 2012, 8:52 pm
RE: static includes issue - bug?
This discussion has been copied to Work Item 3122. You may wish to continue further discussion there.
- Lada Prosek
- Posts: 47
- Joined: January 7th, 2012, 8:52 pm
5 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 8 guests