php-general Digest 27 Aug 2012 04:08:48 -0000 Issue 7938
Topics (messages 318859 through 318869):
Re: syntax error breaking in and out of php into html code
318859 by: tamouse mailing lists
318860 by: Ashley Sheridan
318861 by: Stuart Dallas
318862 by: Ashley Sheridan
318863 by: Samuel Lopes Grigolato
318864 by: Ashley Sheridan
318865 by: Daniel Brown
318866 by: tamouse mailing lists
318867 by: Ashley Sheridan
What's the best way to make a dynamic plugin architecture?
318868 by: Mark
multiple forms one page
318869 by: Rosie Williams
Administrivia:
To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net
To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net
To post to the list, e-mail:
php-gene...@lists.php.net
----------------------------------------------------------------------
--- Begin Message ---
On Sat, Aug 25, 2012 at 9:56 PM, Ashley Sheridan
<a...@ashleysheridan.co.uk> wrote:
> On Sun, 2012-08-26 at 09:41 +0700, Duken Marga wrote:
>
>> Can you tell us what is the error shown in browser or CLI?
>>
>> On Sun, Aug 26, 2012 at 5:54 AM, Ashley Sheridan
>> <a...@ashleysheridan.co.uk>wrote:
>>
>> > I've just inherited some (pretty awful code) that I have to make some
>> > edits to, and came across a bit of a problem. A lot of the code breaks
>> > in and out of PHP and into HTML code:
>> >
>> > <?php
>> > while(condition)
>> > {
>> > ?>
>> > <li>some html here</li>
>> > <?php
>> > }
>> > ?>
>> >
>> > But when I check this my PHP parser is saying that this is a syntax
>> > error (checked in the browser and CLI). I know this is code from a
>> > working site, so it must be a setting within my PHP configuration.
>> >
>> > Now, I'm intending to re-write this anyway, as the logic is all over the
>> > place (SQL queries within the HTML, no separation of code and content,
>> > dozens of warnings all over the place) but I was wondering what setting
>> > causes this. It's mostly a curiosity thing really, as this thing is
>> > going to be re-written faster than an school project the eve before
>> > hand-in.
>> >
>> > --
>> > Thanks,
>> > Ash
>> > http://www.ashleysheridan.co.uk
>> >
>> >
>> >
>>
>>
>
>
> Through the browser I get:
>
> Parse error: syntax error, unexpected $end
> in /var/www/html/siteinquestion/index.php on line 356
>
> Through the CLI I get:
>
> PHP Parse error: syntax error, unexpected $end in index.php on line 356
>
> Parse error: syntax error, unexpected $end in index.php on line 356
>
> Errors parsing index.php
>
> I've narrowed it down to the lines that used the breaking in and out of
> PHP style. As soon as I comment out those it runs fine, albeit without
> the content that code was intended to add.
>
> --
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
I guess I would suspect errant spaces, or a missing closing tag, or
even maybe a short code or something... very hard to say...
--- End Message ---
--- Begin Message ---
On Sun, 2012-08-26 at 04:36 -0500, tamouse mailing lists wrote:
> On Sat, Aug 25, 2012 at 9:56 PM, Ashley Sheridan
> <a...@ashleysheridan.co.uk> wrote:
> > On Sun, 2012-08-26 at 09:41 +0700, Duken Marga wrote:
> >
> >> Can you tell us what is the error shown in browser or CLI?
> >>
> >> On Sun, Aug 26, 2012 at 5:54 AM, Ashley Sheridan
> >> <a...@ashleysheridan.co.uk>wrote:
> >>
> >> > I've just inherited some (pretty awful code) that I have to make some
> >> > edits to, and came across a bit of a problem. A lot of the code breaks
> >> > in and out of PHP and into HTML code:
> >> >
> >> > <?php
> >> > while(condition)
> >> > {
> >> > ?>
> >> > <li>some html here</li>
> >> > <?php
> >> > }
> >> > ?>
> >> >
> >> > But when I check this my PHP parser is saying that this is a syntax
> >> > error (checked in the browser and CLI). I know this is code from a
> >> > working site, so it must be a setting within my PHP configuration.
> >> >
> >> > Now, I'm intending to re-write this anyway, as the logic is all over the
> >> > place (SQL queries within the HTML, no separation of code and content,
> >> > dozens of warnings all over the place) but I was wondering what setting
> >> > causes this. It's mostly a curiosity thing really, as this thing is
> >> > going to be re-written faster than an school project the eve before
> >> > hand-in.
> >> >
> >> > --
> >> > Thanks,
> >> > Ash
> >> > http://www.ashleysheridan.co.uk
> >> >
> >> >
> >> >
> >>
> >>
> >
> >
> > Through the browser I get:
> >
> > Parse error: syntax error, unexpected $end
> > in /var/www/html/siteinquestion/index.php on line 356
> >
> > Through the CLI I get:
> >
> > PHP Parse error: syntax error, unexpected $end in index.php on line 356
> >
> > Parse error: syntax error, unexpected $end in index.php on line 356
> >
> > Errors parsing index.php
> >
> > I've narrowed it down to the lines that used the breaking in and out of
> > PHP style. As soon as I comment out those it runs fine, albeit without
> > the content that code was intended to add.
> >
> > --
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> >
> >
>
> I guess I would suspect errant spaces, or a missing closing tag, or
> even maybe a short code or something... very hard to say...
>
None of the above. This is a working copy of code. It's just to do with
these lines breaking in and out of PHP.
--
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
On 26 Aug 2012, at 03:56, Ashley Sheridan <a...@ashleysheridan.co.uk> wrote:
> Through the browser I get:
>
> Parse error: syntax error, unexpected $end
> in /var/www/html/siteinquestion/index.php on line 356
>
> Through the CLI I get:
>
> PHP Parse error: syntax error, unexpected $end in index.php on line 356
>
> Parse error: syntax error, unexpected $end in index.php on line 356
>
> Errors parsing index.php
>
> I've narrowed it down to the lines that used the breaking in and out of
> PHP style. As soon as I comment out those it runs fine, albeit without
> the content that code was intended to add.
Let me guess, line 356 is the last line of the file? That error is only caused
by mis-matched braces, so the code you are deleting *must* contain either an
errant opening brace or be missing a closing brace.
-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
--- End Message ---
--- Begin Message ---
On Sun, 2012-08-26 at 11:02 +0100, Stuart Dallas wrote:
> On 26 Aug 2012, at 03:56, Ashley Sheridan <a...@ashleysheridan.co.uk> wrote:
>
> > Through the browser I get:
> >
> > Parse error: syntax error, unexpected $end
> > in /var/www/html/siteinquestion/index.php on line 356
> >
> > Through the CLI I get:
> >
> > PHP Parse error: syntax error, unexpected $end in index.php on line 356
> >
> > Parse error: syntax error, unexpected $end in index.php on line 356
> >
> > Errors parsing index.php
> >
> > I've narrowed it down to the lines that used the breaking in and out of
> > PHP style. As soon as I comment out those it runs fine, albeit without
> > the content that code was intended to add.
>
>
> Let me guess, line 356 is the last line of the file? That error is only
> caused by mis-matched braces, so the code you are deleting *must* contain
> either an errant opening brace or be missing a closing brace.
>
> -Stuart
>
> --
> Stuart Dallas
> 3ft9 Ltd
> http://3ft9.com/
It is the last line of the file, but it's not caused by a mismatched
brace. I've tested by deleting just the code in the section where it
breaks out of PHP and it runs without errors. It's a very weird issue,
because this is code that is currently working on another server (which
I don't have access to to match my own setup)
--
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
Maybe you have a "<?" inside the HTML code and your php configuration
allows short open tags? In production that setting could be disabled.
On Sun, Aug 26, 2012 at 9:20 AM, Ashley Sheridan
<a...@ashleysheridan.co.uk>wrote:
> On Sun, 2012-08-26 at 11:02 +0100, Stuart Dallas wrote:
>
> > On 26 Aug 2012, at 03:56, Ashley Sheridan <a...@ashleysheridan.co.uk>
> wrote:
> >
> > > Through the browser I get:
> > >
> > > Parse error: syntax error, unexpected $end
> > > in /var/www/html/siteinquestion/index.php on line 356
> > >
> > > Through the CLI I get:
> > >
> > > PHP Parse error: syntax error, unexpected $end in index.php on line
> 356
> > >
> > > Parse error: syntax error, unexpected $end in index.php on line 356
> > >
> > > Errors parsing index.php
> > >
> > > I've narrowed it down to the lines that used the breaking in and out of
> > > PHP style. As soon as I comment out those it runs fine, albeit without
> > > the content that code was intended to add.
> >
> >
> > Let me guess, line 356 is the last line of the file? That error is only
> caused by mis-matched braces, so the code you are deleting *must* contain
> either an errant opening brace or be missing a closing brace.
> >
> > -Stuart
> >
> > --
> > Stuart Dallas
> > 3ft9 Ltd
> > http://3ft9.com/
>
>
> It is the last line of the file, but it's not caused by a mismatched
> brace. I've tested by deleting just the code in the section where it
> breaks out of PHP and it runs without errors. It's a very weird issue,
> because this is code that is currently working on another server (which
> I don't have access to to match my own setup)
>
> --
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
--- End Message ---
--- Begin Message ---
On Sun, 2012-08-26 at 09:21 -0300, Samuel Lopes Grigolato wrote:
> Maybe you have a "<?" inside the HTML code and your php configuration
> allows short open tags? In production that setting could be disabled.
>
>
> On Sun, Aug 26, 2012 at 9:20 AM, Ashley Sheridan
> <a...@ashleysheridan.co.uk> wrote:
>
> On Sun, 2012-08-26 at 11:02 +0100, Stuart Dallas wrote:
>
> > On 26 Aug 2012, at 03:56, Ashley Sheridan
> <a...@ashleysheridan.co.uk> wrote:
> >
> > > Through the browser I get:
> > >
> > > Parse error: syntax error, unexpected $end
> > > in /var/www/html/siteinquestion/index.php on line 356
> > >
> > > Through the CLI I get:
> > >
> > > PHP Parse error: syntax error, unexpected $end in
> index.php on line 356
> > >
> > > Parse error: syntax error, unexpected $end in index.php on
> line 356
> > >
> > > Errors parsing index.php
> > >
> > > I've narrowed it down to the lines that used the breaking
> in and out of
> > > PHP style. As soon as I comment out those it runs fine,
> albeit without
> > > the content that code was intended to add.
> >
> >
> > Let me guess, line 356 is the last line of the file? That
> error is only caused by mis-matched braces, so the code you
> are deleting *must* contain either an errant opening brace or
> be missing a closing brace.
> >
> > -Stuart
> >
> > --
> > Stuart Dallas
> > 3ft9 Ltd
> > http://3ft9.com/
>
>
>
>
> It is the last line of the file, but it's not caused by a
> mismatched
> brace. I've tested by deleting just the code in the section
> where it
> breaks out of PHP and it runs without errors. It's a very
> weird issue,
> because this is code that is currently working on another
> server (which
> I don't have access to to match my own setup)
>
>
> --
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
>
>
I don't see any, but it could be something along those lines. I turn off
short open tags on my machine, they cause more problems than they solve,
but it's probable that this setting is enabled on the server.
--
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
On Sat, Aug 25, 2012 at 6:54 PM, Ashley Sheridan
<a...@ashleysheridan.co.uk> wrote:
> I've just inherited some (pretty awful code) that I have to make some
> edits to, and came across a bit of a problem. A lot of the code breaks
> in and out of PHP and into HTML code:
>
> <?php
> while(condition)
> {
> ?>
> <li>some html here</li>
> <?php
> }
> ?>
>
> But when I check this my PHP parser is saying that this is a syntax
> error (checked in the browser and CLI). I know this is code from a
> working site, so it must be a setting within my PHP configuration.
>
> Now, I'm intending to re-write this anyway, as the logic is all over the
> place (SQL queries within the HTML, no separation of code and content,
> dozens of warnings all over the place) but I was wondering what setting
> causes this. It's mostly a curiosity thing really, as this thing is
> going to be re-written faster than an school project the eve before
> hand-in.
If it's not a violation of your arrangement with the owner of the
code, Ash, you can send it to me directly, off-list, and I'll take a
look at it. I'm curious to see what might be causing the syntax
errors between PHP deployments as well.
--
</Daniel P. Brown>
Network Infrastructure Manager
http://www.php.net/
--- End Message ---
--- Begin Message ---
On Sun, Aug 26, 2012 at 5:02 AM, Ashley Sheridan
<a...@ashleysheridan.co.uk> wrote:
>
> On Sun, 2012-08-26 at 04:36 -0500, tamouse mailing lists wrote:
>
> On Sat, Aug 25, 2012 at 9:56 PM, Ashley Sheridan
> <a...@ashleysheridan.co.uk> wrote:
> > On Sun, 2012-08-26 at 09:41 +0700, Duken Marga wrote:
> >
> >> Can you tell us what is the error shown in browser or CLI?
> >>
> >> On Sun, Aug 26, 2012 at 5:54 AM, Ashley Sheridan
> >> <a...@ashleysheridan.co.uk>wrote:
> >>
> >> > I've just inherited some (pretty awful code) that I have to make some
> >> > edits to, and came across a bit of a problem. A lot of the code
> >> > breaks
> >> > in and out of PHP and into HTML code:
> >> >
> >> > <?php
> >> > while(condition)
> >> > {
> >> > ?>
> >> > <li>some html here</li>
> >> > <?php
> >> > }
> >> > ?>
> >> >
> >> > But when I check this my PHP parser is saying that this is a syntax
> >> > error (checked in the browser and CLI). I know this is code from a
> >> > working site, so it must be a setting within my PHP configuration.
> >> >
> >> > Now, I'm intending to re-write this anyway, as the logic is all over
> >> > the
> >> > place (SQL queries within the HTML, no separation of code and
> >> > content,
> >> > dozens of warnings all over the place) but I was wondering what
> >> > setting
> >> > causes this. It's mostly a curiosity thing really, as this thing is
> >> > going to be re-written faster than an school project the eve before
> >> > hand-in.
> >> >
> >> > --
> >> > Thanks,
> >> > Ash
> >> > http://www.ashleysheridan.co.uk
> >> >
> >> >
> >> >
> >>
> >>
> >
> >
> > Through the browser I get:
> >
> > Parse error: syntax error, unexpected $end
> > in /var/www/html/siteinquestion/index.php on line 356
> >
> > Through the CLI I get:
> >
> > PHP Parse error: syntax error, unexpected $end in index.php on line 356
> >
> > Parse error: syntax error, unexpected $end in index.php on line 356
> >
> > Errors parsing index.php
> >
> > I've narrowed it down to the lines that used the breaking in and out of
> > PHP style. As soon as I comment out those it runs fine, albeit without
> > the content that code was intended to add.
> >
> > --
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> >
> >
>
> I guess I would suspect errant spaces, or a missing closing tag, or
> even maybe a short code or something... very hard to say...
>
>
> None of the above. This is a working copy of code. It's just to do with
> these lines breaking in and out of PHP.
Byte encodings? Line endings? Sorry, I'm sure you've thought of all this..
--- End Message ---
--- Begin Message ---
On Sun, 2012-08-26 at 09:41 +0700, Duken Marga wrote:
> Can you tell us what is the error shown in browser or CLI?
>
> On Sun, Aug 26, 2012 at 5:54 AM, Ashley Sheridan
> <a...@ashleysheridan.co.uk>wrote:
>
> > I've just inherited some (pretty awful code) that I have to make some
> > edits to, and came across a bit of a problem. A lot of the code breaks
> > in and out of PHP and into HTML code:
> >
> > <?php
> > while(condition)
> > {
> > ?>
> > <li>some html here</li>
> > <?php
> > }
> > ?>
> >
> > But when I check this my PHP parser is saying that this is a syntax
> > error (checked in the browser and CLI). I know this is code from a
> > working site, so it must be a setting within my PHP configuration.
> >
> > Now, I'm intending to re-write this anyway, as the logic is all over the
> > place (SQL queries within the HTML, no separation of code and content,
> > dozens of warnings all over the place) but I was wondering what setting
> > causes this. It's mostly a curiosity thing really, as this thing is
> > going to be re-written faster than an school project the eve before
> > hand-in.
> >
> > --
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> >
> >
> >
>
>
Well, it turns out that I'm just an idiot. I'd missed where a couple of
short tags had been used!
--
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
Hi,
Envision the following plugin architecture:
class PluginLoader
{
}
interface PluginInterface
{
.. some function definitions ..
}
class PluginOne implements PluginInterface
{
}
class PluginTwo implements PluginInterface
{
}
The PluginLoader is loading the plugins.
The PluginInterface defines an interface which each plugin has to implement.
PluginOne and PluginTwo are plugins that implement the interface.
Each plugin (PluginOne and PluginTwo) are stored in their own folders.
So the folder structure would be somewhat like this:
|- Plugins
|- - PluginOne
|- - - PluginOne.php
|- - - other possible files
|- - PluginTwo
|- - - PluginTwo.php
|- - - other possible files
|- PluginLoader.php
|- PluginInterface.php
Now making this structure isn't an issue. I can do all of that just
fine. The place where i'm actually going to make a plugin instance is
where things get a little more complicated. The PluginLoader simply
reads all the dirs in the Plugins folder and tries to find a filename
with the same dir. So if it reads the dir Plugins/PluginOne it will
try to include the PHP file: Plugins/PluginOne/PluginOne.php. That's
fine and working.
To actually make a plugin instance i can do two things that i know of:
1. use eval like so: eval('$obj = new '.$pluginName.'();'); and
register it to the PluginLoader.
2. Let the plugin itself (so in this case PluginOne.php) open itself
and register it to the PluginLoader.
With the first option i have to do eval which i try to avoid if possible.
With the second solution the PluginLoader probably has to be a singlethon.
Now my question is: what is the right way of loading plugins like
this? Is there some other option then the two i described above? My
PHP limitations are the newest version so no limitation there :)
I'm kinda leaning towards the second option now since that seems to be
quite stable and not very error prone. The eval one is much easier to
break :p
Cheers,
Mark
--- End Message ---
--- Begin Message ---
Hi all,
I am a newbie to PHP. I have several php forms which were originally on
separate pages now included in the one page. Each form had the following code
in it:
function mysql_fix_string($string){ if (get_magic_quotes_gpc()) $string =
stripslashes($string); return mysql_real_escape_string($string);}
function mysql_entities_fix_string($string){ return
htmlentities(mysql_fix_string($string));}
However I am only able to include it in one of the forms on the new page with
multiple scripts due to the fatal error that I can only declare the function
once. So for testing I have commented these lines out of the other scripts. I
need to know what the security implications of this are? Do the scripts that do
not contain these lines run without it or is it included automatically every
time the database is accessed regardless of which script is accessing it?
If not how do I deal with it?
thanks in advanceRosie
--- End Message ---