Please see:
https://wiki.php.net/rfc/source_files_without_opening_tag
After following the discussion I have updated the RFC with the
following major changes:
-
Forbade the use of ?> entirely in "pure PHP" files (without
restricting it at all in other PHP files) -
Replaced my original new require_path keyword with a second,
optional parameter to the standard include/require family of keywords -
Replaced an array of options with a bitwise OR of options
-
Changed the proposed filename extension from .phpc (which apparently
is in use somewhere, maybe?) to .phpp ("php pure")
--
Tom Boutell
P'unk Avenue
215 755 1330
punkave.com
window.punkave.com
Tom,
Please see:
https://wiki.php.net/rfc/source_files_without_opening_tag
After following the discussion I have updated the RFC with the
following major changes:
Forbade the use of ?> entirely in "pure PHP" files (without
restricting it at all in other PHP files)Replaced my original new require_path keyword with a second,
optional parameter to the standard include/require family of keywordsReplaced an array of options with a bitwise OR of options
Changed the proposed filename extension from .phpc (which apparently
is in use somewhere, maybe?) to .phpp ("php pure")--
Tom Boutell
P'unk Avenue
215 755 1330
punkave.com
window.punkave.com--
Much better, though I'm still very troubled by allowing non-pure PHP code
to be mixed-in with pure PHP (by means of includes). The problem I have
with this, as a developer, is that this means I can't really trust that
what I will get from a "pure PHP" script will actually be pure PHP, because
non-pure scripts lower in the stack might mix-in HTML code that would then
get passed up through the stack. These really shouldn't be mixed anyway,
so I'm just not seeing any value in not keeping this separation consistent.
I'd be able to support this if that one remaining problem is fixed. I
still would like to see the ability to add a <?phpp tag to a regular .php
file, but I can always propose that as a separate RFC later on so that's
not a deal-breaker for me. But the lack of standards consistency is a
deal-breaker, for me at least. :/
--Kris
Tom,
Much better, though I'm still very troubled by allowing non-pure PHP code to
be mixed-in with pure PHP (by means of includes). The problem I have with
this, as a developer, is that this means I can't really trust that what I
will get from a "pure PHP" script will actually be pure PHP, because
non-pure scripts lower in the stack might mix-in HTML code that would then
get passed up through the stack. These really shouldn't be mixed anyway, so
I'm just not seeing any value in not keeping this separation consistent.
The approach you suggest would make it impossible to load an existing
library of perfectly good classes from a newer framework. I don't know
anyone who would be able to get work done under those circumstances (:
It would lead to almost no adoption of the new feature.
Whereas if we make this feature easy to adopt, and strict within the
files it does apply to, then over time we would see more and more
.phpp and less and less .php. Mission accomplished. Sometimes a
realistic compromise is the long term way to get to a better place.
Think through what will likely happen in the real world under various
proposals, and not just what would be most pure (:
--
Tom Boutell
P'unk Avenue
215 755 1330
punkave.com
window.punkave.com
Tom,
Much better, though I'm still very troubled by allowing non-pure PHP
code to
be mixed-in with pure PHP (by means of includes). The problem I have
with
this, as a developer, is that this means I can't really trust that what I
will get from a "pure PHP" script will actually be pure PHP, because
non-pure scripts lower in the stack might mix-in HTML code that would
then
get passed up through the stack. These really shouldn't be mixed
anyway, so
I'm just not seeing any value in not keeping this separation consistent.The approach you suggest would make it impossible to load an existing
library of perfectly good classes from a newer framework. I don't know
anyone who would be able to get work done under those circumstances (:
It would lead to almost no adoption of the new feature.
This shouldn't be used to load libraries that dump raw HTML output! That
literally defeats the entire purpose. You're also assuming that all PHP
developers do 100% of their coding through pre-existing frameworks.
If you're including a library that contains embedded HTML, you should do so
from a regular .php file. Then you can include the .phpp file at that same
level, thereby avoiding the collision.
For example, here's what you're suggesting:
-------------- (Main Script) ------------
| |
| |
[Included .php/HTML Script] {Included .phpp Script}
|
|
[Included .php/HTML Script from Framework/Library]
That approach is bad architecture and simply unnecessary. If you want to
interface with that library, do it like this instead:
(Main Script)
|
|
[Included .php/HTML Script]
| |
| |
{Included .phpp Script} [Included .php/HTML Script from
Framework/Library]
In other words, instead of calling that third-party, HTML-containing
library from the .phpp file, call both it and the .phpp file from a regular
.php file, which will then act as the "controller" and bridge the
functionality between the two. This would be a far more sane architecture,
anyway. And it allows you to achieve the exact same result, without having
to have included HTML bits polluting the upstream from the pure PHP stack.
Make sense? I'm just not seeing any value in breaking this model just so
that bad, lazy architecture that shouldn't be used in the first place can
be supported.
Whereas if we make this feature easy to adopt, and strict within the
files it does apply to, then over time we would see more and more
.phpp and less and less .php. Mission accomplished. Sometimes a
realistic compromise is the long term way to get to a better place.Think through what will likely happen in the real world under various
proposals, and not just what would be most pure (:
See above. =)
--
Tom Boutell
P'unk Avenue
215 755 1330
punkave.com
window.punkave.com
This shouldn't be used to load libraries that dump raw HTML output! That
literally defeats the entire purpose. You're also assuming that all PHP
developers do 100% of their coding through pre-existing frameworks.
Consider a .phpp file that includes a .php template file when it sees
fit, in a render() method. How is this different from an echo()
statement? It's not. It's just a convenient form in some situations.
By punting these out to .php files we achieve better separation of
concerns while still respecting PHP's history as a template language
(and possible future if it improves in that area, which it may).
All I want is to stop typing <?php and dealing with whitespace
screwups above <?php. I want to do that in a way that's practical and
interoperable and which people might be able to vote for if they have
a nontrivial amount of legacy code in their life, like everybody I
work with (:
As many have pointed out, plain php template files work for some
projects. A viable RFC that people might actually vote for should
respect that. It neither picks my pocket nor breaks my leg if someone
wants to include .php template files from a .phpp file. I don't have
to do it.
When you consider that I would be completely unable to use an existing
.php library of nontrival code like Amazon's S3 SDK under your
proposal without a convoluted workaround it is pretty much a certainty
that I would have to vote no if the RFC read that way.
(Main Script)
|
|
[Included .php/HTML Script]
| |
| |
{Included .phpp Script} [Included .php/HTML Script from
Framework/Library]
This is convoluted and forces me to write a .php frontend. Surely that
is not your goal.
--
Tom Boutell
P'unk Avenue
215 755 1330
punkave.com
window.punkave.com
This shouldn't be used to load libraries that dump raw HTML output! That
literally defeats the entire purpose. You're also assuming that all PHP
developers do 100% of their coding through pre-existing frameworks.Consider a .phpp file that includes a .php template file when it sees
fit, in a render() method. How is this different from an echo()
statement? It's not. It's just a convenient form in some situations.
By punting these out to .php files we achieve better separation of
concerns while still respecting PHP's history as a template language
(and possible future if it improves in that area, which it may).
Again, this can easily be made to work using a simple MVC architecture.
I.e. the "view" layer calls controller::render(), which then includes
model.phpp and funnels the call to model::render(). Again, this is just
basic segregation of model (i.e. "pure") code from view (i.e. template)
code. This is already widely considered best practices, so having this
conform to that is not a bad thing. On the other hand, your approach makes
it impossible to determine absolutely that the model code will remain pure,
thus rendering this whole RFC completely and utterly useless IMHO.
All I want is to stop typing <?php and dealing with whitespace
screwups above <?php. I want to do that in a way that's practical and
interoperable and which people might be able to vote for if they have
a nontrivial amount of legacy code in their life, like everybody I
work with (:
I know. But unfortunately, for reasons already discussed ad nauseum, the
only way to truly accomplish that without weighing other factors would be
to massively break all PHP scripts that currently exist. You may want to
just have a simple removal of <?php, but it's not that simple so you should
probably adjust your expectations accordingly.
As many have pointed out, plain php template files work for some
projects. A viable RFC that people might actually vote for should
respect that. It neither picks my pocket nor breaks my leg if someone
wants to include .php template files from a .phpp file. I don't have
to do it.
Again, if you're concerned about that, then you have no business including
them within a .phpp file to begin with. It's basically like turning on the
shower but then covering the nozzle with a stopper so that no water will
come out, allowing you to "take a shower" while still remaining dirty. If
you want to stay covered in dirt, then don't take a shower! If you do take
a shower, then you have no business doing so if your goal isn't to get
clean. That would just make no sense.
When you consider that I would be completely unable to use an existing
.php library of nontrival code like Amazon's S3 SDK under your
proposal without a convoluted workaround it is pretty much a certainty
that I would have to vote no if the RFC read that way.
That's a logical fallacy because it's based on a faulty premise. I.e.
"....I would be completely unable to use.... without a convoluted
workaround...."
That statement is inaccurate because there is no "workaround," convoluted
or otherwise. It's just standard MVC architecture, which is neither
convoluted nor uncommon. If somebody wanted to be able to write a script
containing class instantiation but keep the code 100% procedural, most
people would tell that person to rethink that idea. He could say that
having to define a class is a "convoluted workaround," but it's not.
Instead of having your .phpp script call a script containing HTML, and thus
essentially having your .phpp file contain HTML and thus be no different on
a practical level than a regular .php file, just have a regular .php script
that calls both the .phpp file and the .php library. That's not
complicated. In fact, it's insultingly simple. If you want it to be pure
PHP, then it needs to be pure PHP throughout its stack (i.e. includes).
Either way, it needs to be consistent. Your approach would add far too
much complexity/confusion without any practical gain, whatsoever (aside
from not having to type that 5-character <?php tag).
(Main Script) | | [Included .php/HTML Script] | | | |
{Included .phpp Script} [Included .php/HTML Script from
Framework/Library]This is convoluted and forces me to write a .php frontend. Surely that
is not your goal.
I think the problem is you're trying to have it both ways. No, you are not
forced to write a .php frontend. You can send whatever HTML/template
output you need through echo/print/etc, without ever having to use the ?>
tag.
Furthermore, if you're including a library with HTML bits, then I'd say the
ship has already sailed with regard to having a .php frontend. If you
don't wany any .php frontend in your code, then simply don't use a library
that relies on it. Simple as that. If you so want to include the library,
then simply make sure that there are no .php/HTML frontend files below it
in the stack, which is what you should be doing anyway.
Also, the model above is just one example, and it's not complicated. In
fact, it contains all the same stuff as the bad example model above it; the
only difference is that the .php and .phpp scripts are on the same level
instead of .phpp calling a .php file that contains raw HTML code.
--
Tom Boutell
P'unk Avenue
215 755 1330
punkave.com
window.punkave.com
I had no goal of making sure code "remains pure" in this rfc, only the goal of being allowed to write pure code (no opening <?php ) and establishing a way to encourage pure code in the scope of individual class files (disallowing ?> in individual pure mode files). I think an easy, obvious bc mechanism is essential, making it harder to use legacy code is not something people would vote for, and more pure code is better than no pure code. You feel differently. I'm not sure our positions can be reconciled. Perhaps this point will just have to be settled when the rfc is voted on.
Sent from my iPhone
This shouldn't be used to load libraries that dump raw HTML output! That
literally defeats the entire purpose. You're also assuming that all PHP
developers do 100% of their coding through pre-existing frameworks.Consider a .phpp file that includes a .php template file when it sees
fit, in a render() method. How is this different from an echo()
statement? It's not. It's just a convenient form in some situations.
By punting these out to .php files we achieve better separation of
concerns while still respecting PHP's history as a template language
(and possible future if it improves in that area, which it may).Again, this can easily be made to work using a simple MVC architecture. I.e. the "view" layer calls controller::render(), which then includes model.phpp and funnels the call to model::render(). Again, this is just basic segregation of model (i.e. "pure") code from view (i.e. template) code. This is already widely considered best practices, so having this conform to that is not a bad thing. On the other hand, your approach makes it impossible to determine absolutely that the model code will remain pure, thus rendering this whole RFC completely and utterly useless IMHO.
All I want is to stop typing <?php and dealing with whitespace
screwups above <?php. I want to do that in a way that's practical and
interoperable and which people might be able to vote for if they have
a nontrivial amount of legacy code in their life, like everybody I
work with (:I know. But unfortunately, for reasons already discussed ad nauseum, the only way to truly accomplish that without weighing other factors would be to massively break all PHP scripts that currently exist. You may want to just have a simple removal of <?php, but it's not that simple so you should probably adjust your expectations accordingly.
As many have pointed out, plain php template files work for some
projects. A viable RFC that people might actually vote for should
respect that. It neither picks my pocket nor breaks my leg if someone
wants to include .php template files from a .phpp file. I don't have
to do it.Again, if you're concerned about that, then you have no business including them within a .phpp file to begin with. It's basically like turning on the shower but then covering the nozzle with a stopper so that no water will come out, allowing you to "take a shower" while still remaining dirty. If you want to stay covered in dirt, then don't take a shower! If you do take a shower, then you have no business doing so if your goal isn't to get clean. That would just make no sense.
When you consider that I would be completely unable to use an existing
.php library of nontrival code like Amazon's S3 SDK under your
proposal without a convoluted workaround it is pretty much a certainty
that I would have to vote no if the RFC read that way.That's a logical fallacy because it's based on a faulty premise. I.e. "....I would be completely unable to use.... without a convoluted workaround...."
That statement is inaccurate because there is no "workaround," convoluted or otherwise. It's just standard MVC architecture, which is neither convoluted nor uncommon. If somebody wanted to be able to write a script containing class instantiation but keep the code 100% procedural, most people would tell that person to rethink that idea. He could say that having to define a class is a "convoluted workaround," but it's not.
Instead of having your .phpp script call a script containing HTML, and thus essentially having your .phpp file contain HTML and thus be no different on a practical level than a regular .php file, just have a regular .php script that calls both the .phpp file and the .php library. That's not complicated. In fact, it's insultingly simple. If you want it to be pure PHP, then it needs to be pure PHP throughout its stack (i.e. includes). Either way, it needs to be consistent. Your approach would add far too much complexity/confusion without any practical gain, whatsoever (aside from not having to type that 5-character <?php tag).
(Main Script) | | [Included .php/HTML Script] | | | |
{Included .phpp Script} [Included .php/HTML Script from
Framework/Library]This is convoluted and forces me to write a .php frontend. Surely that
is not your goal.I think the problem is you're trying to have it both ways. No, you are not forced to write a .php frontend. You can send whatever HTML/template output you need through echo/print/etc, without ever having to use the ?> tag.
Furthermore, if you're including a library with HTML bits, then I'd say the ship has already sailed with regard to having a .php frontend. If you don't wany any .php frontend in your code, then simply don't use a library that relies on it. Simple as that. If you so want to include the library, then simply make sure that there are no .php/HTML frontend files below it in the stack, which is what you should be doing anyway.
Also, the model above is just one example, and it's not complicated. In fact, it contains all the same stuff as the bad example model above it; the only difference is that the .php and .phpp scripts are on the same level instead of .phpp calling a .php file that contains raw HTML code.
--
Tom Boutell
P'unk Avenue
215 755 1330
punkave.com
window.punkave.com
I had no goal of making sure code "remains pure" in this rfc, only the
goal of being allowed to write pure code (no opening <?php ) and
establishing a way to encourage pure code in the scope of individual class
files (disallowing ?> in individual pure mode files). I think an easy,
obvious bc mechanism is essential, making it harder to use legacy code is
not something people would vote for, and more pure code is better than no
pure code. You feel differently. I'm not sure our positions can be
reconciled. Perhaps this point will just have to be settled when the rfc is
voted on.
Indeed. Looks like I'll just have to draft an RFC of my own then. So now
that will make 3 competing RFCs on this subject.... grumble
Sent from my iPhone
On Tue, Apr 10, 2012 at 10:10 PM, Kris Craig kris.craig@gmail.com
wrote:This shouldn't be used to load libraries that dump raw HTML output!
That
literally defeats the entire purpose. You're also assuming that all
PHP
developers do 100% of their coding through pre-existing frameworks.Consider a .phpp file that includes a .php template file when it sees
fit, in a render() method. How is this different from an echo()
statement? It's not. It's just a convenient form in some situations.
By punting these out to .php files we achieve better separation of
concerns while still respecting PHP's history as a template language
(and possible future if it improves in that area, which it may).Again, this can easily be made to work using a simple MVC architecture.
I.e. the "view" layer calls controller::render(), which then includes
model.phpp and funnels the call to model::render(). Again, this is just
basic segregation of model (i.e. "pure") code from view (i.e. template)
code. This is already widely considered best practices, so having this
conform to that is not a bad thing. On the other hand, your approach makes
it impossible to determine absolutely that the model code will remain pure,
thus rendering this whole RFC completely and utterly useless IMHO.All I want is to stop typing <?php and dealing with whitespace
screwups above <?php. I want to do that in a way that's practical and
interoperable and which people might be able to vote for if they have
a nontrivial amount of legacy code in their life, like everybody I
work with (:I know. But unfortunately, for reasons already discussed ad nauseum,
the only way to truly accomplish that without weighing other factors would
be to massively break all PHP scripts that currently exist. You may want
to just have a simple removal of <?php, but it's not that simple so you
should probably adjust your expectations accordingly.As many have pointed out, plain php template files work for some
projects. A viable RFC that people might actually vote for should
respect that. It neither picks my pocket nor breaks my leg if someone
wants to include .php template files from a .phpp file. I don't have
to do it.Again, if you're concerned about that, then you have no business
including them within a .phpp file to begin with. It's basically like
turning on the shower but then covering the nozzle with a stopper so that
no water will come out, allowing you to "take a shower" while still
remaining dirty. If you want to stay covered in dirt, then don't take a
shower! If you do take a shower, then you have no business doing so if
your goal isn't to get clean. That would just make no sense.When you consider that I would be completely unable to use an existing
.php library of nontrival code like Amazon's S3 SDK under your
proposal without a convoluted workaround it is pretty much a certainty
that I would have to vote no if the RFC read that way.That's a logical fallacy because it's based on a faulty premise. I.e.
"....I would be completely unable to use.... without a convoluted
workaround...."That statement is inaccurate because there is no "workaround,"
convoluted or otherwise. It's just standard MVC architecture, which is
neither convoluted nor uncommon. If somebody wanted to be able to write a
script containing class instantiation but keep the code 100% procedural,
most people would tell that person to rethink that idea. He could say that
having to define a class is a "convoluted workaround," but it's not.Instead of having your .phpp script call a script containing HTML, and
thus essentially having your .phpp file contain HTML and thus be no
different on a practical level than a regular .php file, just have a
regular .php script that calls both the .phpp file and the .php library.
That's not complicated. In fact, it's insultingly simple. If you want it
to be pure PHP, then it needs to be pure PHP throughout its stack (i.e.
includes). Either way, it needs to be consistent. Your approach would add
far too much complexity/confusion without any practical gain, whatsoever
(aside from not having to type that 5-character <?php tag).(Main Script) | | [Included .php/HTML Script] | | | |
{Included .phpp Script} [Included .php/HTML Script from
Framework/Library]This is convoluted and forces me to write a .php frontend. Surely that
is not your goal.I think the problem is you're trying to have it both ways. No, you are
not forced to write a .php frontend. You can send whatever HTML/template
output you need through echo/print/etc, without ever having to use the ?>
tag.Furthermore, if you're including a library with HTML bits, then I'd say
the ship has already sailed with regard to having a .php frontend. If you
don't wany any .php frontend in your code, then simply don't use a library
that relies on it. Simple as that. If you so want to include the library,
then simply make sure that there are no .php/HTML frontend files below it
in the stack, which is what you should be doing anyway.Also, the model above is just one example, and it's not complicated. In
fact, it contains all the same stuff as the bad example model above it; the
only difference is that the .php and .phpp scripts are on the same level
instead of .phpp calling a .php file that contains raw HTML code.--
Tom Boutell
P'unk Avenue
215 755 1330
punkave.com
window.punkave.com
Please see:
https://wiki.php.net/rfc/source_files_without_opening_tag
After following the discussion I have updated the RFC with the
following major changes:
Forbade the use of ?> entirely in "pure PHP" files (without
restricting it at all in other PHP files)Replaced my original new require_path keyword with a second,
optional parameter to the standard include/require family of keywordsReplaced an array of options with a bitwise OR of options
Changed the proposed filename extension from .phpc (which apparently
is in use somewhere, maybe?) to .phpp ("php pure")
Looks good, however:
- I would like to see an INCLUDE_SILENT method to prevent warnings from
being thrown with include/include_once statements. Currently doing
something like @include "/path/to/file.php"; not only hides these
warnings, but warnings/errors/notices thrown by the file itself. An
INCLUDE_SILENT flag would be extremely helpful in some situations.
Example:
if(class_exists("MyClass")) // Auto loader is used
{
// Class exists, continue normal...
}
else
{
// Class doesn't exist, do stuff... but warnings are being thrown!
Eeek!
}
(An INCLUDE_SILENT is probably the most important to me)
-
The INCLUDE_ONCE and INCLUDE_ERROR_ON_FAILURE are a bit redundant.
Wouldn't you just use require or include_once/require_once? -
Not sure I like the word "pure code". I would prefer just "code" -
INCLUDE_CODE. Perhaps even just "pure" - INCLUDE_PURE. I just don't like
two words. Would also like another flag for the other mode, such as
INCLUDE_TEMPLATE or INCLUDE_EMBED. -
I would like to be able to specify the mode as an environmental variable
from the web server, perhaps "PHP_MODE". So I could do something like this
in my Nginx config:
location / {
fastcgi_pass unix:/Server/tmp/php-fpm.sock;
include fastcgi_params;
fastcgi_param PHP_MODE "pure";
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_param SCRIPT_NAME /index.php;
fastcgi_param HTTP_ACCEPT_ENCODING "";
fastcgi_param HTTPS $https;
}
Luke
- I would like to see an INCLUDE_SILENT method to prevent warnings from
being thrown with include/include_once statements. Currently doing
something like @include "/path/to/file.php"; not only hides these
warnings, but warnings/errors/notices thrown by the file itself. An
INCLUDE_SILENT flag would be extremely helpful in some situations.
I almost included this, but wasn't sure how you would actually become
aware of the error at that point. class_exists is probably a valid
answer to that. It would be dangerous to use the INCLUDE_SILENT for
any include file that wasn't a class. The return value of 'include' is
the return value of the code it executed, so we can't use that. How
about INCLUDE_EXCEPTION?
This is really a separate issue, but it's true it would make a lot of
sense to add this bit at the same time.
- The INCLUDE_ONCE and INCLUDE_ERROR_ON_FAILURE are a bit redundant.
Wouldn't you just use require or include_once/require_once?
I like being able to do things dynamically without writing a switch
statement. As we move toward having more bit flags, why not have the
option of using flags for the existing distinctions as well (as long
as you start with plain old 'include')?
- Not sure I like the word "pure code". I would prefer just "code" -
INCLUDE_CODE. Perhaps even just "pure" - INCLUDE_PURE. I just don't like
two words. Would also like another flag for the other mode, such as
INCLUDE_TEMPLATE or INCLUDE_EMBED.
These are bits, so INCLUDE_TEMPLATE would just be zero. Not sure it
makes sense to have that as an explicit flag.
- I would like to be able to specify the mode as an environmental variable
from the web server, perhaps "PHP_MODE". So I could do something like this
in my Nginx config:location / {
fastcgi_pass unix:/Server/tmp/php-fpm.sock;
include fastcgi_params;
fastcgi_param PHP_MODE "pure";
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_param SCRIPT_NAME /index.php;
fastcgi_param HTTP_ACCEPT_ENCODING "";
fastcgi_param HTTPS $https;
}
I almost included this too but I am a little fatigued thinking about
all the details (:
Can we arrange it so that .php and .phpp each do the right thing under
fastcgi without creating two process pools? Is configuring FPM similar
to configuring the classic CGI SAPI for FastCGI operation?
A -p option for CLI and plain CGI is simple enough at least.
I personally don't mind all that much if entry point PHP files don't
get this feature but of course I see that others would like it. And
one day it would be nice to alias phpp to php -p and write PHP one-off
scripts without <?php.
--
Tom Boutell
P'unk Avenue
215 755 1330
punkave.com
window.punkave.com
- I would like to see an INCLUDE_SILENT method to prevent warnings from
being thrown with include/include_once statements. Currently doing
something like @include "/path/to/file.php"; not only hides these
warnings, but warnings/errors/notices thrown by the file itself. An
INCLUDE_SILENT flag would be extremely helpful in some situations.I almost included this, but wasn't sure how you would actually become
aware of the error at that point. class_exists is probably a valid
answer to that. It would be dangerous to use the INCLUDE_SILENT for
any include file that wasn't a class. The return value of 'include' is
the return value of the code it executed, so we can't use that. How
about INCLUDE_EXCEPTION?
That would be slightly better as you could then catch the exception.
But it doesn't make sense to do this in an auto loader because you'll
always be including classes. It would also add unnecessary overhead
having to catch the exception.
For me INCLUDE_BOTH is absolutely necessary.
Why not add both?
This is really a separate issue, but it's true it would make a lot of
sense to add this bit at the same time.
- The INCLUDE_ONCE and INCLUDE_ERROR_ON_FAILURE are a bit redundant.
Wouldn't you just use require or include_once/require_once?I like being able to do things dynamically without writing a switch
statement. As we move toward having more bit flags, why not have the
option of using flags for the existing distinctions as well (as long
as you start with plain old 'include')?
I'm not sure it can be dynamic being a construct.
- Not sure I like the word "pure code". I would prefer just "code" -
INCLUDE_CODE. Perhaps even just "pure" - INCLUDE_PURE. I just don't like
two words. Would also like another flag for the other mode, such as
INCLUDE_TEMPLATE or INCLUDE_EMBED.These are bits, so INCLUDE_TEMPLATE would just be zero. Not sure it
makes sense to have that as an explicit flag.
I suppose that makes sense. Still, could define it as zero.
- I would like to be able to specify the mode as an environmental variable
from the web server, perhaps "PHP_MODE". So I could do something like this
in my Nginx config:location / {
fastcgi_pass unix:/Server/tmp/php-fpm.sock;
include fastcgi_params;
fastcgi_param PHP_MODE "pure";
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_param SCRIPT_NAME /index.php;
fastcgi_param HTTP_ACCEPT_ENCODING "";
fastcgi_param HTTPS $https;
}I almost included this too but I am a little fatigued thinking about
all the details (:Can we arrange it so that .php and .phpp each do the right thing under
fastcgi without creating two process pools? Is configuring FPM similar
to configuring the classic CGI SAPI for FastCGI operation?
In order for it to work you need an environmental variable. You can
use the same pool, Nginx just needs a way to tell PHP what mode to use
for what extension.
In my case I'd configure Nginx to send all requests to Index.php in
pure mode, as I have shown in my config sample.
A -p option for CLI and plain CGI is simple enough at least.
I personally don't mind all that much if entry point PHP files don't
get this feature but of course I see that others would like it. And
one day it would be nice to alias phpp to php -p and write PHP one-off
scripts without <?php.
Don't forget to mention "pure" mode can optionally start with <?php as
it's the first token.
Luke
Tom Boutell wrote:
- Forbade the use of ?> entirely in "pure PHP" files (without
restricting it at all in other PHP files)
Just as long as we can just carry on ignoring that rule if we want to ...
And I don't have to worry about major libraries slipping this in and screwing up
'old fashioned php' systems.
Heck - PLEASE can we have an off switch ... although I'd rather you just dropped
the whole thing! If I see a <? I know it's PHP and with all the <% I'm having to
work with it's nice to KNOW it's php ...
--
Lester Caine - G8HFL
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php
Hi,
As I stated already, the only valid reason to have pure php source
(non embed mode) would be better security than now.
Writing start tags is not burden. Unless it provides better security
like my proposal,
https://wiki.php.net/rfc/nophptags
I cannot support it.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
Hello,
Please see:
https://wiki.php.net/rfc/source_files_without_opening_tag
After following the discussion I have updated the RFC with the
following major changes:
Forbade the use of ?> entirely in "pure PHP" files (without
restricting it at all in other PHP files)Replaced my original new require_path keyword with a second,
optional parameter to the standard include/require family of keywordsReplaced an array of options with a bitwise OR of options
Changed the proposed filename extension from .phpc (which apparently
is in use somewhere, maybe?) to .phpp ("php pure")
I have read the RFC and I although from what I gather it seems that
.phpp is a recommendation and not a requirement, but I want to make
absolutely sure.
My only other issue is that we are not really following the guidelines
for reserved constants, since "include" is not part of a "include"
extension and a actual language construct it feels like it should live
inside the reserved PHP_* constants. There may be projects that make
use of "INCLUDE_ONCE" as a constant or maybe not, regardless I think
it should follow the documented naming guidelines to be safe.
-Chris
On Wed, Apr 11, 2012 at 1:48 PM, Chris Stockton
chrisstocktonaz@gmail.com wrote:
I have read the RFC and I although from what I gather it seems that
.phpp is a recommendation and not a requirement, but I want to make
absolutely sure.
That is correct, it is not a requirement. However if you know of any
reason why .phpp would be a bad choice of file extension for PHP
source files without <?php and ?> in them, now would be a good time to
share that input.
My only other issue is that we are not really following the guidelines
for reserved constants, since "include" is not part of a "include"
extension and a actual language construct it feels like it should live
inside the reserved PHP_* constants. There may be projects that make
use of "INCLUDE_ONCE" as a constant or maybe not, regardless I think
it should follow the documented naming guidelines to be safe.
I wasn't aware of those guidelines. This makes sense to me.
PHP_INCLUDE_ONCE, then?
--
Tom Boutell
P'unk Avenue
215 755 1330
punkave.com
window.punkave.com
Hello,
On Wed, Apr 11, 2012 at 1:48 PM, Chris Stockton
chrisstocktonaz@gmail.com wrote:I have read the RFC and I although from what I gather it seems that
.phpp is a recommendation and not a requirement, but I want to make
absolutely sure.That is correct, it is not a requirement. However if you know of any
reason why .phpp would be a bad choice of file extension for PHP
source files without <?php and ?> in them, now would be a good time to
share that input.
Something about PHP advocating it makes me feel a little uneasy, I
guess it can at least help frameworks have a unified standard for
their auto loaders etc. My main concern is people expecting .phpp will
"just work" when including via apache on shared hosting servers etc.
End up with a file full of code, passwords, who knows what downloaded
or displayed in a browser. The burden of responsibility here is not
entirely clear for me, but I am just not sure I like proposing a
separate PHP extension, just seems a little wrong. However from what I
see no one else has said anything so perhaps I am wrong. I will say if
I was developing a framework I might try to think of other
alternatives for my auto loading / detecting of pure php files. I.E.a
specific folder like "purephplib" a specific portion of the file name
or something like "Class_Name_Pure" (like this much less then folders,
but I think more then a file extension. Just my two cents.
My only other issue is that we are not really following the guidelines
for reserved constants, since "include" is not part of a "include"
extension and a actual language construct it feels like it should live
inside the reserved PHP_* constants. There may be projects that make
use of "INCLUDE_ONCE" as a constant or maybe not, regardless I think
it should follow the documented naming guidelines to be safe.I wasn't aware of those guidelines. This makes sense to me.
PHP_INCLUDE_ONCE, then?
I will let others comment here, was just my initial thoughts.
-Chris
Hi,
I think script only include should have it own function, since
it's the current semantics of PHP.
require/require_once/include/include_once why not script/script_once?
Stats give an interesting idea. It can be normal function.
How about write a PECL module for it?
You can do that by scanning PHP script by lex_scan() and validate
it, then execute. For script_once(), just lookup if it is loaded already.
For token scan, you might want to take a look at tokenizer source.
Looking forward your module.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net