RE: [PHP-GENERAL] Parse errors with includes and/or prepends/appends PROPOSAL
| From: | Christopher Thompson | Date: | Tue, 13 Jun 2000 20:35:57 +0000 |
| Subject: | RE: [PHP-GENERAL] Parse errors with includes and/or prepends/appends PROPOSAL | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-1751@lists.php.net to get a copy of this message | ||
This changed from PHP3 to PHP4 and is no longer allowed. This is
unfortunate because I was doing the same thing you are, which is a fairly
elegant solution and transparent to other files. I have also heard that
there seem to be some complaints about include_once() and require_once()
not sharing the same history lists.
I have a modest proposal to the developers:
Implement a language construct that allows more control on how files are
merged by having two parameters, the filespec followed by flags to define
how the file is to be merged. I think it would be a powerful advantage
over other languages. Perhaps you could resurrect the use() keyword for
this. Here are some examples of the idea:
# current require()
use ("dir/myfile.php", USE_PARSE | USE_ALWAYS);
# current include()
use ("dir/myfile.php", USE_PARSE | USE_IF_NEEDED);
# current require_once()
use ("dir/myfile.php", USE_PARSE | USE_ALWAYS | USE_ONCE);
# current include_once()
use ("dir/myfile.php", USE_PARSE | USE_IF_NEEDED | USE_ONCE);
It could also do what Seth and I want in the form:
# just merge the text into the main file before parsing
use ("dir/myfile.php", USE_ALWAYS);
It could be extend it a la Perl to create the idea of library with a
header or for compiled code:
# require() and read lib header
use ("dir/myfile.php", USE_ALWAYS | USE_PARSE | USE_PACKAGE);
> -----Original Message-----
> From: Seth Hollyman [mailto:seth@isis.awc.cc.az.us]
> Sent: Tuesday, June 13, 2000 11:50 AM
> To: php-general@lists.php.net
> Subject: [PHP-GENERAL] Parse errors with includes and/or
> prepends/appends
>
>
>
> Hello. I'm trying to write a web interface for a management system that
> relies on session handlers and authentication. I've got a file with all
> the requisite functions, as well as code snippets that need to go at the
> top and bottom of every page in this interface system.
>
> It seems that php can't handle including only part of a logical block in
> one file and the other part in a second.
>
> When I try and include() or require() the files at the top and bottom of
> the documents, or use the auto_prepend_file and auto_append_file
> directives in the apache configuration file, I get parse
> errors. It seems
> that the php engine tries to evaluate each seperately.
>
>
> Example:
>
> prependfile.inc:
> <?php
> session_start();
> include("authlib.inc");
> // Do some auth checks here
> if ($AuthFlag == 1) {
> ?>
>
> appendfile.inc
> <?php
> } else {
> include("authform.inc");
> }
> ?>
>
> The parse error seems to die on the "if" line in the prepended
> file. However, if all the code is present on the page (not
> included/required in), the page works as it should.
>
> How can I force the code to be appended/prepended, and then have it
> evaluated as one unit? Or, am I just missing something obvious here?
>
> Seth
> seth@isis.awc.cc.az.us
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>