php-general Digest 18 Aug 2010 20:46:03 -0000 Issue 6900

Topics (messages 307519 through 307544):

Re: tutorial failure
        307519 by: Arno Kuhl
        307520 by: Peter Lind
        307521 by: e-letter
        307522 by: chris h
        307523 by: e-letter
        307524 by: Peter Lind
        307525 by: e-letter
        307526 by: chris h
        307527 by: e-letter
        307528 by: chris h
        307529 by: e-letter
        307530 by: Ashley Sheridan
        307531 by: e-letter
        307532 by: Bob McConnell
        307534 by: e-letter

Re: mysqldump
        307533 by: Daniel P. Brown

method overloading in a class
        307535 by: Ashley Sheridan
        307536 by: chris h
        307541 by: Ashley Sheridan
        307542 by: Adam Richardson

Regular expressions, filter option1 OR option2
        307537 by: Camilo Sperberg
        307538 by: Shreyas Agasthya
        307540 by: Ashley Sheridan
        307543 by: Camilo Sperberg

SSL Timeout Issue with fopen, fsockopen, file_get_contents, etc
        307539 by: Brent Macnaughton

Can't read $_POST array
        307544 by: Brian Dunning

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 ---
-----Original Message-----
From: e-letter [mailto:inp...@gmail.com] 
Sent: 18 August 2010 10:44 AM
To: php-gene...@lists.php.net
Subject: [PHP] tutorial failure

Readers,

Copy below of message sent 15 August to php install digest list, but to date
not including in mail archive?

The tutorial example:

<html>
      <head>
              <title>php test
              </title
      </head>
      <body>
              <?php
                      echo '<p>Hi, I am a PHP script</p>';
              ?>
              <p>
              this is a test
              </p>
      </body>
</html>

is saved to the normal user temporary folder as 'test.php' and then copied
to the folder '/var/www/html/' using the root user account. The web browser
is directed to url 'http://localhost.test.php, to show:

Hi, I am a PHP script

'; ?>

this is a test

What is the error please?

Urpmi was used to install so the php version installed is not known.
How to obtain this please

--

Shouldn't that be http://localhost/test.php

Cheers
Arno



--- End Message ---
--- Begin Message ---
On 18 August 2010 10:44, e-letter <inp...@gmail.com> wrote:
> Readers,
>
> Copy below of message sent 15 August to php install digest list, but
> to date not including in mail archive?
>
> The tutorial example:
>
> <html>
>      <head>
>              <title>php test
>              </title
>      </head>
>      <body>
>              <?php
>                      echo '<p>Hi, I am a PHP script</p>';
>              ?>
>              <p>
>              this is a test
>              </p>
>      </body>
> </html>
>
> is saved to the normal user temporary folder as 'test.php' and then
> copied to the folder '/var/www/html/' using the root user account. The
> web browser is directed to url 'http://localhost.test.php, to show:
>
> Hi, I am a PHP script
>
> '; ?>
>
> this is a test
>
> What is the error please?

Looks like a problem with quotes, I'd say.

> Urpmi was used to install so the php version installed is not known.
> How to obtain this please

Check with php -i from the command line or a script containing
phpinfo(); requested through the browser.

Regards
Peter

-- 
<hype>
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
</hype>

--- End Message ---
--- Begin Message ---
I changed the code as follows:

<html>
        <head>
                <title>php test
                </title>
        </head>
        <body>
                <?php phpinfo ?>
                <?php
                        echo "<p>Hi, I am a PHP script</p>";
                ?>
                <p>
                this is a test
                </p>
        </body>
</html>

The result (http://localhost/test.php):

Hi, I am a PHP script

"; ?>

this is a test

If I use single quotes characters:

Hi, I am a PHP script

'; ?>

this is a test

The phpinfo instruction does not seem to be recognised. What else
should I check?

--- End Message ---
--- Begin Message ---
php is not processing the file.  There's a few reasons for this, but the
first thing I would check is the permissions of the file.  From the
directory try

$ ls -oa

This should tell you who owns the file and what it's permissions are.  You
mentioned that you copied it as root, you could change it's ownership to
www-data.

again from the directory try.

$ chown www-data test.php

then run ls -oa to ensure the change took place.


Chris.

On Wed, Aug 18, 2010 at 6:03 AM, e-letter <inp...@gmail.com> wrote:

> I changed the code as follows:
>
> <html>
>        <head>
>                <title>php test
>                </title>
>        </head>
>        <body>
>                 <?php phpinfo ?>
>                 <?php
>                        echo "<p>Hi, I am a PHP script</p>";
>                ?>
>                <p>
>                this is a test
>                </p>
>        </body>
> </html>
>
> The result (http://localhost/test.php):
>
> Hi, I am a PHP script
>
> "; ?>
>
> this is a test
>
> If I use single quotes characters:
>
> Hi, I am a PHP script
>
> '; ?>
>
> this is a test
>
> The phpinfo instruction does not seem to be recognised. What else
> should I check?
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
On 18/08/2010, chris h <chris...@gmail.com> wrote:
> php is not processing the file.  There's a few reasons for this, but the
> first thing I would check is the permissions of the file.  From the
> directory try
>
> $ ls -oa
>
The file permission was confirmed as root, since it was copied (as
root) from a normal user account directorp 'temporary' to the
directory '/var/www/html'

> This should tell you who owns the file and what it's permissions are.  You
> mentioned that you copied it as root, you could change it's ownership to
> www-data.
>
This fails:

[r...@localhost html]# chown www-data test.php
chown: `www-data': invalid user

So I repeated this with a normal user account and the change in
permission occurs. However, the html file containing the php script
remains unchanged.

The instruction:

...
<?php phpinfo() ?>
...

Does not show the version of php.

--- End Message ---
--- Begin Message ---
On 18 August 2010 12:47, e-letter <inp...@gmail.com> wrote:
> On 18/08/2010, chris h <chris...@gmail.com> wrote:
>> php is not processing the file.  There's a few reasons for this, but the
>> first thing I would check is the permissions of the file.  From the
>> directory try
>>
>> $ ls -oa
>>
> The file permission was confirmed as root, since it was copied (as
> root) from a normal user account directorp 'temporary' to the
> directory '/var/www/html'
>
>> This should tell you who owns the file and what it's permissions are.  You
>> mentioned that you copied it as root, you could change it's ownership to
>> www-data.
>>
> This fails:
>
> [r...@localhost html]# chown www-data test.php
> chown: `www-data': invalid user
>
> So I repeated this with a normal user account and the change in
> permission occurs. However, the html file containing the php script
> remains unchanged.
>
> The instruction:
>
> ...
> <?php phpinfo() ?>
> ...
>
> Does not show the version of php.
>

Your webserver might not be configured to process php files - which
server are you using?

Regards
Peter

-- 
<hype>
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
</hype>

--- End Message ---
--- Begin Message ---
On 18/08/2010, Peter Lind <peter.e.l...@gmail.com> wrote:
> On 18 August 2010 12:47, e-letter <inp...@gmail.com> wrote:
>> On 18/08/2010, chris h <chris...@gmail.com> wrote:
>>> php is not processing the file.  There's a few reasons for this, but the
>>> first thing I would check is the permissions of the file.  From the
>>> directory try
>>>
>>> $ ls -oa
>>>
>> The file permission was confirmed as root, since it was copied (as
>> root) from a normal user account directorp 'temporary' to the
>> directory '/var/www/html'
>>
>>> This should tell you who owns the file and what it's permissions are.
>>>  You
>>> mentioned that you copied it as root, you could change it's ownership to
>>> www-data.
>>>
>> This fails:
>>
>> [r...@localhost html]# chown www-data test.php
>> chown: `www-data': invalid user
>>
>> So I repeated this with a normal user account and the change in
>> permission occurs. However, the html file containing the php script
>> remains unchanged.
>>
>> The instruction:
>>
>> ...
>> <?php phpinfo() ?>
>> ...
>>
>> Does not show the version of php.
>>
>
> Your webserver might not be configured to process php files - which
> server are you using?
>
Apache. Below is an extract of an (to now) unanswered question:

...
<FilesMatch \.php$>
   SetHandler application/x-httpd-php
</FilesMatch

Apparently this should be part of the addtype directive. I don't
understand which file I am to edit and add the code shown above.
...

So perhaps apache is not configured but I don't know how to test this.

--- End Message ---
--- Begin Message ---
What are the actual file permissions when you run ls -o?


Do you know if PHP is installed as an apache mod or cgi? Also you might
check what user apache is running as.

possibly...
$ vi /etc/apache2/envvars

and look for something like...
export APACHE_RUN_USER=www-data




On Wed, Aug 18, 2010 at 6:47 AM, e-letter <inp...@gmail.com> wrote:

> On 18/08/2010, chris h <chris...@gmail.com> wrote:
> > php is not processing the file.  There's a few reasons for this, but the
> > first thing I would check is the permissions of the file.  From the
> > directory try
> >
> > $ ls -oa
> >
> The file permission was confirmed as root, since it was copied (as
> root) from a normal user account directorp 'temporary' to the
> directory '/var/www/html'
>
> > This should tell you who owns the file and what it's permissions are.
>  You
> > mentioned that you copied it as root, you could change it's ownership to
> > www-data.
> >
> This fails:
>
> [r...@localhost html]# chown www-data test.php
> chown: `www-data': invalid user
>
> So I repeated this with a normal user account and the change in
> permission occurs. However, the html file containing the php script
> remains unchanged.
>
> The instruction:
>
> ...
> <?php phpinfo() ?>
> ...
>
> Does not show the version of php.
>

--- End Message ---
--- Begin Message ---
On 18/08/2010, chris h <chris...@gmail.com> wrote:
> What are the actual file permissions when you run ls -o?
>
root
>
> Do you know if PHP is installed as an apache mod or cgi? Also you might
> check what user apache is running as.
>
No. How to verify?

> possibly...
> $ vi /etc/apache2/envvars
>
No apache2 on my computer, only '/usr/lib/apache' which contains only .so files.

--- End Message ---
--- Begin Message ---
On Wed, Aug 18, 2010 at 7:10 AM, e-letter <inp...@gmail.com> wrote:

> On 18/08/2010, chris h <chris...@gmail.com> wrote:
> > What are the actual file permissions when you run ls -o?
> >
> root
>

What's the entire output of ls -o?


> >
> > Do you know if PHP is installed as an apache mod or cgi? Also you might
> > check what user apache is running as.
> >
> No. How to verify?
>
> > possibly...
> > $ vi /etc/apache2/envvars
> >
> No apache2 on my computer, only '/usr/lib/apache' which contains only .so
> files.
>

there's no /etc/apache either?

--- End Message ---
--- Begin Message ---
On 18/08/2010, chris h <chris...@gmail.com> wrote:
> On Wed, Aug 18, 2010 at 7:10 AM, e-letter <inp...@gmail.com> wrote:
>
>> On 18/08/2010, chris h <chris...@gmail.com> wrote:
>> > What are the actual file permissions when you run ls -o?
>> >
>> root
>>
>
> What's the entire output of ls -o?
>
[r...@localhost html]# ls -o *
-rwxr-xr-x 1 root  182 2010-08-18 11:33 test.php*

addon-modules:
total 4
lrwxrwxrwx 1 root  51 2010-01-11 22:03 apache-mod_svn_view-0.1.0 ->
../../../../usr/share/doc/apache-mod_svn_view-0.1.0
lrwxrwxrwx 1 root  52 2010-01-11 22:03 apache-mod_transform-0.6.0 ->
../../../../usr/share/doc/apache-mod_transform-0.6.0
-rw-r--r-- 1 root 115 2007-09-07 21:47 HOWTO_get_modules.html

>
>> >
>> > Do you know if PHP is installed as an apache mod or cgi? Also you might
>> > check what user apache is running as.
>> >
>> No. How to verify?
>>
>> > possibly...
>> > $ vi /etc/apache2/envvars
>> >
>> No apache2 on my computer, only '/usr/lib/apache' which contains only .so
>> files.
>>
>
> there's no /etc/apache either?
>
No

--- End Message ---
--- Begin Message ---
On Wed, 2010-08-18 at 12:10 +0100, e-letter wrote:

> On 18/08/2010, chris h <chris...@gmail.com> wrote:
> > What are the actual file permissions when you run ls -o?
> >
> root
> >
> > Do you know if PHP is installed as an apache mod or cgi? Also you might
> > check what user apache is running as.
> >
> No. How to verify?
> 
> > possibly...
> > $ vi /etc/apache2/envvars
> >
> No apache2 on my computer, only '/usr/lib/apache' which contains only .so 
> files.
> 


ls -o doesn't give one word answers, so again, what is the output of an
ls -o call in your shell?

I assume that root is the owner of the file here, and the fact that
you're getting some output from it seems to suggest that at least read
permissions are available for group and other, but you should check to
see if the permissions are indeed something like 664 (-rw-rw-r--)

What OS are you using? I'm assuming a Linux distro of some kind here,
but it could also be another Unix variant. Have you tried using the
package manager within the distro (if it is Linux) to install PHP and
Apache together? That makes it a lot easier to get up and running with a
decent configuration, especially if you're unfamiliar with the more
complicated details.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
On 18/08/2010, Ashley Sheridan <a...@ashleysheridan.co.uk> wrote:
> On Wed, 2010-08-18 at 12:10 +0100, e-letter wrote:
>
>> On 18/08/2010, chris h <chris...@gmail.com> wrote:
>> > What are the actual file permissions when you run ls -o?
>> >
>> root
>> >
>> > Do you know if PHP is installed as an apache mod or cgi? Also you might
>> > check what user apache is running as.
>> >
>> No. How to verify?
>>
>> > possibly...
>> > $ vi /etc/apache2/envvars
>> >
>> No apache2 on my computer, only '/usr/lib/apache' which contains only .so
>> files.
>>
>
>
> ls -o doesn't give one word answers, so again, what is the output of an
> ls -o call in your shell?
>
> I assume that root is the owner of the file here, and the fact that
> you're getting some output from it seems to suggest that at least read
> permissions are available for group and other, but you should check to
> see if the permissions are indeed something like 664 (-rw-rw-r--)
>
> What OS are you using? I'm assuming a Linux distro of some kind here,
> but it could also be another Unix variant. Have you tried using the
> package manager within the distro (if it is Linux) to install PHP and
> Apache together? That makes it a lot easier to get up and running with a
> decent configuration, especially if you're unfamiliar with the more
> complicated details.
>
I used urpmi with mandriva

--- End Message ---
--- Begin Message ---
From: e-letter

> On 18/08/2010, chris h <chris...@gmail.com> wrote:
>> On Wed, Aug 18, 2010 at 7:10 AM, e-letter <inp...@gmail.com> wrote:
>>
>>> On 18/08/2010, chris h <chris...@gmail.com> wrote:
>>> > What are the actual file permissions when you run ls -o?
>>> >
>>> root
>>>
>>
>> What's the entire output of ls -o?
>>
> [r...@localhost html]# ls -o *
> -rwxr-xr-x 1 root  182 2010-08-18 11:33 test.php*
> 
> addon-modules:
> total 4
> lrwxrwxrwx 1 root  51 2010-01-11 22:03 apache-mod_svn_view-0.1.0 ->
> ../../../../usr/share/doc/apache-mod_svn_view-0.1.0
> lrwxrwxrwx 1 root  52 2010-01-11 22:03 apache-mod_transform-0.6.0 ->
> ../../../../usr/share/doc/apache-mod_transform-0.6.0
> -rw-r--r-- 1 root 115 2007-09-07 21:47 HOWTO_get_modules.html
> 
>>
>>> >
>>> > Do you know if PHP is installed as an apache mod or cgi? Also you
might
>>> > check what user apache is running as.
>>> >
>>> No. How to verify?
>>>
>>> > possibly...
>>> > $ vi /etc/apache2/envvars
>>> >
>>> No apache2 on my computer, only '/usr/lib/apache' which contains
only .so
>>> files.
>>>
>>
>> there's no /etc/apache either?
>>
> No

Some distributions have really screwed up the locations of various
applications. This is compounded by the decision to rename the Apache 2
directories to httpd. Look for /etc/httpd, /home/httpd or
/usr/lib/httpd. If worse comes to worst, try

ps ax | grep httpd

 to see if you can find the path from the original start up in the init
process.

Bob McConnell

--- End Message ---
--- Begin Message ---
On 18/08/2010, Bob McConnell <r...@cbord.com> wrote:
> From: e-letter
>
>> On 18/08/2010, chris h <chris...@gmail.com> wrote:
>>> On Wed, Aug 18, 2010 at 7:10 AM, e-letter <inp...@gmail.com> wrote:
>>>
>>>> On 18/08/2010, chris h <chris...@gmail.com> wrote:
>>>> > What are the actual file permissions when you run ls -o?
>>>> >
>>>> root
>>>>
>>>
>>> What's the entire output of ls -o?
>>>
>> [r...@localhost html]# ls -o *
>> -rwxr-xr-x 1 root  182 2010-08-18 11:33 test.php*
>>
>> addon-modules:
>> total 4
>> lrwxrwxrwx 1 root  51 2010-01-11 22:03 apache-mod_svn_view-0.1.0 ->
>> ../../../../usr/share/doc/apache-mod_svn_view-0.1.0
>> lrwxrwxrwx 1 root  52 2010-01-11 22:03 apache-mod_transform-0.6.0 ->
>> ../../../../usr/share/doc/apache-mod_transform-0.6.0
>> -rw-r--r-- 1 root 115 2007-09-07 21:47 HOWTO_get_modules.html
>>
>>>
>>>> >
>>>> > Do you know if PHP is installed as an apache mod or cgi? Also you
> might
>>>> > check what user apache is running as.
>>>> >
>>>> No. How to verify?
>>>>
>>>> > possibly...
>>>> > $ vi /etc/apache2/envvars
>>>> >
>>>> No apache2 on my computer, only '/usr/lib/apache' which contains
> only .so
>>>> files.
>>>>
>>>
>>> there's no /etc/apache either?
>>>
>> No
>
> Some distributions have really screwed up the locations of various
> applications. This is compounded by the decision to rename the Apache 2
> directories to httpd. Look for /etc/httpd, /home/httpd or
> /usr/lib/httpd. If worse comes to worst, try
>
In '/etc/httpd/conf' there is an empty directory 'addon-modules'. In
/usr/lib/apache-extramodules there is 'mod_php5.so'.

--- End Message ---
--- Begin Message ---
On Tue, Aug 17, 2010 at 15:19, tedd <t...@sperling.com> wrote:
>
> Bingo -- that worked.
>
> It's interesting that a space is optional between -u and user, but required
> to be absent between -p and password. Seems not symmetrical to me.

    The command I sent was because - as I said in the original thread
- passing any password directly to the command line is Very Bad[tm].
If you're passing it via exec(), though, and don't want to use an
'expect' shell, passing it directly to -p is at least a bit less
dangerous.  Plus, doing so will not leave anything in your
~/.bash_history on the server.

    That said, sorry for appearing inattentive, despite this being
directed right at me.  I have been out of the office more than in for
the last couple of weeks, while working on a ton of new stuff.
Eventually it will go back to "normal."

-- 
</Daniel P. Brown>
UNADVERTISED DEDICATED SERVER SPECIALS
SAME-DAY SETUP
Just ask me what we're offering today!
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/

--- End Message ---
--- Begin Message ---
Hi list,

I know that some languages such as C++ can overload functions and
methods by declaring the method again with a different number of
arguments, and the compiler internally sorts things out, but I can't
seem to find a similar way to do this with PHP.

Basically, what I've got at the moment is a class method with 2
arguments, and I need to be able to overload the method with 3
arguments. The following which would work in other languages doesn't
seem to bring any joy in PHP:

class foo
{
    public function bar($arg1, $arg2)
   {
        // do something with $arg1 & $arg2
    }

    public function bar($arg1, $arg2, $arg3)
    {
        // do something different with all 3 args
    }
}

Is there any feasible way of doing this? The method names really need to
remain the same as they exist as part of a framework, but the arguments
really server quite different purposes between the two methods, so
there's no nice way of just merging the two functions without breaking
the naming conventions, etc used.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
Would something like this work for you?

class foo
{

   public function bar($arg1, $arg2, $arg3=null)
  {

     if (isset($arg3)){
     {
        return $this->_bar3($arg1, $arg2, $arg3);

     } else {
        return $this->_bar2($arg1, $arg2);

     }

  }


also you may want to look into the func_get_args function.



Chris.


On Wed, Aug 18, 2010 at 12:23 PM, Ashley Sheridan
<a...@ashleysheridan.co.uk>wrote:

> Hi list,
>
> I know that some languages such as C++ can overload functions and
> methods by declaring the method again with a different number of
> arguments, and the compiler internally sorts things out, but I can't
> seem to find a similar way to do this with PHP.
>
> Basically, what I've got at the moment is a class method with 2
> arguments, and I need to be able to overload the method with 3
> arguments. The following which would work in other languages doesn't
> seem to bring any joy in PHP:
>
> class foo
> {
>    public function bar($arg1, $arg2)
>   {
>        // do something with $arg1 & $arg2
>    }
>
>    public function bar($arg1, $arg2, $arg3)
>    {
>        // do something different with all 3 args
>    }
> }
>
> Is there any feasible way of doing this? The method names really need to
> remain the same as they exist as part of a framework, but the arguments
> really server quite different purposes between the two methods, so
> there's no nice way of just merging the two functions without breaking
> the naming conventions, etc used.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>

--- End Message ---
--- Begin Message ---
On Wed, 2010-08-18 at 12:35 -0400, chris h wrote:
> 
> 
> Would something like this work for you?
> 
> 
> class foo
> {
> 
> 
>    public function bar($arg1, $arg2, $arg3=null)
>   {
> 
> 
>      if (isset($arg3)){
>      {
>         return $this->_bar3($arg1, $arg2, $arg3);
> 
> 
>      } else {
>         return $this->_bar2($arg1, $arg2);
> 
> 
>      }
> 
> 
> 
>   }
> 
> 
> 
> 
> also you may want to look into the func_get_args function.
> 
> 
> 
> 
> 
> 
> 
> Chris.
> 
> 
> 
> 
> 
> 
> On Wed, Aug 18, 2010 at 12:23 PM, Ashley Sheridan
> <a...@ashleysheridan.co.uk> wrote:
> 
>         Hi list,
>         
>         I know that some languages such as C++ can overload functions
>         and
>         methods by declaring the method again with a different number
>         of
>         arguments, and the compiler internally sorts things out, but I
>         can't
>         seem to find a similar way to do this with PHP.
>         
>         Basically, what I've got at the moment is a class method with
>         2
>         arguments, and I need to be able to overload the method with 3
>         arguments. The following which would work in other languages
>         doesn't
>         seem to bring any joy in PHP:
>         
>         class foo
>         {
>            public function bar($arg1, $arg2)
>           {
>                // do something with $arg1 & $arg2
>            }
>         
>            public function bar($arg1, $arg2, $arg3)
>            {
>                // do something different with all 3 args
>            }
>         }
>         
>         Is there any feasible way of doing this? The method names
>         really need to
>         remain the same as they exist as part of a framework, but the
>         arguments
>         really server quite different purposes between the two
>         methods, so
>         there's no nice way of just merging the two functions without
>         breaking
>         the naming conventions, etc used.
>         
>         Thanks,
>         Ash
>         http://www.ashleysheridan.co.uk
>         
>         
> 
> 

Thanks to everyone, I decided to modify the existing original method and
use func_get_args() to grab the arguments passed to it. It's not
perfect, because I lose out on the automatic value assignment that I
would have with a regular method (i.e. function foo($bar, $fubar=0) etc)
but it will do at a pinch.

It's a shame this sort of overloading isn't supported, as it could be
quite a useful feature, but it's not a complete show-stopper.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
On Wed, Aug 18, 2010 at 12:23 PM, Ashley Sheridan
<a...@ashleysheridan.co.uk>wrote:

> Hi list,
>
> I know that some languages such as C++ can overload functions and
> methods by declaring the method again with a different number of
> arguments, and the compiler internally sorts things out, but I can't
> seem to find a similar way to do this with PHP.
>
> Basically, what I've got at the moment is a class method with 2
> arguments, and I need to be able to overload the method with 3
> arguments. The following which would work in other languages doesn't
> seem to bring any joy in PHP:
>
> class foo
> {
>    public function bar($arg1, $arg2)
>   {
>        // do something with $arg1 & $arg2
>    }
>
>    public function bar($arg1, $arg2, $arg3)
>    {
>        // do something different with all 3 args
>    }
> }
>
> Is there any feasible way of doing this? The method names really need to
> remain the same as they exist as part of a framework, but the arguments
> really server quite different purposes between the two methods, so
> there's no nice way of just merging the two functions without breaking
> the naming conventions, etc used.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
Hi Ashley,

Sorry for a slow reply, but I've found a free second and I'd like to toss
out the scheme I've used most often.

If args 1 and 2 are consistent in terms of type and usage across the two
methods, I simply add arg3 with a default to null and conditionally call a
private method that performs the special operation (documentation and
primary entry point remain in one place.  Essentially, I just add a guard
clause to the original function.  The

class foo
{
   public function bar($arg1, $arg2, $arg3 = null)
  {
       if (!is_null($arg3)) return _specialbar($arg1, $arg2, $arg3);

       // do something with $arg1 & $arg2
   }

   public function _specialbar($arg1, $arg2, $arg3)
   {
       // do something different with all 3 args
   }
}

If, however, the functions differ significantly in terms of signature, I
tend to write a wrapper function that chooses the appropriate internal call
(e.g., newbar()), but this doesn't play too nicely with documentation within
the PHP ecosystem (although within other language systems such as Java, C#,
and Erlang, it's really quite nice and elegant), so I tend to structure my
code to make use of option one when possible.

Adam

-- 
Nephtali:  PHP web framework that functions beautifully
http://nephtaliproject.com

--- End Message ---
--- Begin Message ---
Hello list :)

Just a short question which I know it should be easy, but I'm no expert yet
in regular expressions.
I've got a nice little XML string, which is something like this but can be
changed:

<?xml version="1.0" encoding="utf-8"?>
<boolean xmlns="http://tempuri.org/";>false</boolean>

The boolean value can be true or false, so what I want to do, is filter it.
I've done it this way, but I know it can be improved (just because I love
clean coding and also because I want to master regular expressions xD):

  $result = preg_match('/true/',$curl_response);
  if ($result == 0) $result = preg_match('/false/',$curl_response);

I've also tried something like:
$result = preg_replace('/^(true)|^(false)/','',$curl_response); // if not
true OR not false => replace with empty

and also '/^true|^false/' which doesn't seem to work.

Any ideas to filter this kind of string in just one expression?

Thanks in advance :)

-- 
Mailed by:
UnReAl4U - unreal4u
ICQ #: 54472056
www1: http://www.chw.net/
www2: http://unreal4u.com/

--- End Message ---
--- Begin Message ---
Camilo,

What exactly are you trying to achieve? Meaning:

if (true)
   do this;
if (false)
   do that;

However, here's a link that I used long back to help me with some RegEx :
http://www.gskinner.com/RegExr/

Regards,
Shreyas

On Wed, Aug 18, 2010 at 11:31 PM, Camilo Sperberg <csperb...@unreal4u.com>wrote:

> Hello list :)
>
> Just a short question which I know it should be easy, but I'm no expert yet
> in regular expressions.
> I've got a nice little XML string, which is something like this but can be
> changed:
>
> <?xml version="1.0" encoding="utf-8"?>
> <boolean xmlns="http://tempuri.org/";>false</boolean>
>
> The boolean value can be true or false, so what I want to do, is filter it.
> I've done it this way, but I know it can be improved (just because I love
> clean coding and also because I want to master regular expressions xD):
>
>  $result = preg_match('/true/',$curl_response);
>  if ($result == 0) $result = preg_match('/false/',$curl_response);
>
> I've also tried something like:
> $result = preg_replace('/^(true)|^(false)/','',$curl_response); // if not
> true OR not false => replace with empty
>
> and also '/^true|^false/' which doesn't seem to work.
>
> Any ideas to filter this kind of string in just one expression?
>
> Thanks in advance :)
>
> --
> Mailed by:
> UnReAl4U - unreal4u
> ICQ #: 54472056
> www1: http://www.chw.net/
> www2: http://unreal4u.com/
>



-- 
Regards,
Shreyas Agasthya

--- End Message ---
--- Begin Message ---
On Wed, 2010-08-18 at 23:36 +0530, Shreyas Agasthya wrote:

> Camilo,
> 
> What exactly are you trying to achieve? Meaning:
> 
> if (true)
>    do this;
> if (false)
>    do that;
> 
> However, here's a link that I used long back to help me with some RegEx :
> http://www.gskinner.com/RegExr/
> 
> Regards,
> Shreyas
> 
> On Wed, Aug 18, 2010 at 11:31 PM, Camilo Sperberg 
> <csperb...@unreal4u.com>wrote:
> 
> > Hello list :)
> >
> > Just a short question which I know it should be easy, but I'm no expert yet
> > in regular expressions.
> > I've got a nice little XML string, which is something like this but can be
> > changed:
> >
> > <?xml version="1.0" encoding="utf-8"?>
> > <boolean xmlns="http://tempuri.org/";>false</boolean>
> >
> > The boolean value can be true or false, so what I want to do, is filter it.
> > I've done it this way, but I know it can be improved (just because I love
> > clean coding and also because I want to master regular expressions xD):
> >
> >  $result = preg_match('/true/',$curl_response);
> >  if ($result == 0) $result = preg_match('/false/',$curl_response);
> >
> > I've also tried something like:
> > $result = preg_replace('/^(true)|^(false)/','',$curl_response); // if not
> > true OR not false => replace with empty
> >
> > and also '/^true|^false/' which doesn't seem to work.
> >
> > Any ideas to filter this kind of string in just one expression?
> >
> > Thanks in advance :)
> >
> > --
> > Mailed by:
> > UnReAl4U - unreal4u
> > ICQ #: 54472056
> > www1: http://www.chw.net/
> > www2: http://unreal4u.com/
> >
> 
> 
> 


As far as I can tell, are you just trying to grab the content from the
<boolean> tag text node? If it's limited to this basic example, there's
likely not much of a need to use dedicated DOM functions, but consider
using them if you need to work on more complex documents.

If you are just trying to determine if the value is indeed true or false
and nothing else, then a regex could be overkill here. As you only need
to check two values, consider:

if(strpos($xml, 'true') || strpos($xml, 'false'))
{
    // text node content is OK
}
else
{
    // bad, bad input, go sit in the corner
}

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
On Wed, Aug 18, 2010 at 15:01, Ashley Sheridan <a...@ashleysheridan.co.uk>wrote:

>  On Wed, 2010-08-18 at 23:36 +0530, Shreyas Agasthya wrote:
>
> Camilo,
>
> What exactly are you trying to achieve? Meaning:
>
> if (true)
>    do this;
> if (false)
>    do that;
>
> However, here's a link that I used long back to help me with some RegEx 
> :http://www.gskinner.com/RegExr/
>
> Regards,
> Shreyas
>
> On Wed, Aug 18, 2010 at 11:31 PM, Camilo Sperberg 
> <csperb...@unreal4u.com>wrote:
>
> > Hello list :)
> >
> > Just a short question which I know it should be easy, but I'm no expert yet
> > in regular expressions.
> > I've got a nice little XML string, which is something like this but can be
> > changed:
> >
> > <?xml version="1.0" encoding="utf-8"?>
> > <boolean xmlns="http://tempuri.org/";>false</boolean>
> >
> > The boolean value can be true or false, so what I want to do, is filter it.
> > I've done it this way, but I know it can be improved (just because I love
> > clean coding and also because I want to master regular expressions xD):
> >
> >  $result = preg_match('/true/',$curl_response);
> >  if ($result == 0) $result = preg_match('/false/',$curl_response);
> >
> > I've also tried something like:
> > $result = preg_replace('/^(true)|^(false)/','',$curl_response); // if not
> > true OR not false => replace with empty
> >
> > and also '/^true|^false/' which doesn't seem to work.
> >
> > Any ideas to filter this kind of string in just one expression?
> >
> > Thanks in advance :)
> >
> > --
> > Mailed by:
> > UnReAl4U - unreal4u
> > ICQ #: 54472056
> > www1: http://www.chw.net/
> > www2: http://unreal4u.com/
> >
>
>
>
>
>
> As far as I can tell, are you just trying to grab the content from the
> <boolean> tag text node? If it's limited to this basic example, there's
> likely not much of a need to use dedicated DOM functions, but consider using
> them if you need to work on more complex documents.
>
> If you are just trying to determine if the value is indeed true or false
> and nothing else, then a regex could be overkill here. As you only need to
> check two values, consider:
>
> if(strpos($xml, 'true') || strpos($xml, 'false'))
> {
>     // text node content is OK
> }
> else
> {
>     // bad, bad input, go sit in the corner
> }
>
>
Indeed Ashley, I'm trying to get the TRUE / FALSE value from the boolean
tag.

After reading again, you're absolutely right: strpos does just what I need
it to do: a simple search for a true or false. (Or null, in which case
strpos will be FALSE anyway).

Thanks for your suggestion, I was doing an overkill here.

@Shreyas: thanks for the link! It is very helpful to speed up the testing a
bit!

Greetings!


-- 
Mailed by:
UnReAl4U - unreal4u
ICQ #: 54472056
www1: http://www.chw.net/
www2: http://unreal4u.com/

--- End Message ---
--- Begin Message ---
I am really in need of some help here! Whenever I try to use fopen,
fsockopen, file_get_contents, etc in php to open an https/ssl; resource, i
get the following errors:

Warning: file_get_contents(): SSL: connection timeout
Warning: file_get_contents(): Failed to enable crypto

Here is some relevant information from phpinfo():

OpenSSL support     enabled
OpenSSL Version     OpenSSL 0.9.8n 24 Mar 2010
Registered Stream Socket Transports     tcp, udp, unix, udg, ssl, sslv3,
sslv2, tls
Registered PHP Streams     https, ftps, compress.zlib, compress.bzip2, php,
file, data, http, ftp
allow_url_fopen    On
default_socket_timeout    60

The SSL connection timeout message occurs immediately. The server is not
blocking outbound communications as a tcpdump on the server that php is
trying to connect to shows connection activity, however, the apache and php
logs on this server do not show any entries at all when php tries to connect
to it.

On the server with php installed on it, openssl appears to be installed
correctly.

----------------------------------------------------------
[r...@rdcsol-10-01]# /opt/csw/bin/openssl version
OpenSSL 0.9.8n 24 Mar 2010
[r...@rdcsol-10-01]# /opt/csw/bin/openssl s_client -connect
www<dot>google<dot>com:443
CONNECTED(00000004)
depth=1 /C=ZA/O=Thawte Consulting (Pty) Ltd./CN=Thawte SGC CA
verify error:num=20:unable to get local issuer certificate
verify return:0
---
Certificate chain
 0 s:/C=US/ST=California/L=Mountain View/O=Google
Inc/CN=www<dot>google<dot>com
   i:/C=ZA/O=Thawte Consulting (Pty) Ltd./CN=Thawte SGC CA
 1 s:/C=ZA/O=Thawte Consulting (Pty) Ltd./CN=Thawte SGC CA
   i:/C=US/O=VeriSign, Inc./OU=Class 3 Public Primary Certification
Authority
---
Server certificate
-----BEGIN CERTIFICATE-----
MIIDITCCAoqgAwIBAgIQL9+89q6RUm0PmqPfQDQ+mjANBgkqhkiG9w0BAQUFADBM
MQswCQYDVQQGEwJaQTElMCMGA1UEChMcVGhhd3RlIENvbnN1bHRpbmcgKFB0eSkg
THRkLjEWMBQGA1UEAxMNVGhhd3RlIFNHQyBDQTAeFw0wOTEyMTgwMDAwMDBaFw0x
MTEyMTgyMzU5NTlaMGgxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlh
MRYwFAYDVQQHFA1Nb3VudGFpbiBWaWV3MRMwEQYDVQQKFApHb29nbGUgSW5jMRcw
FQYDVQQDFA53d3cuZ29vZ2xlLmNvbTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkC
gYEA6PmGD5D6htffvXImttdEAoN4c9kCKO+IRTn7EOh8rqk41XXGOOsKFQebg+jN
gtXj9xVoRaELGYW84u+E593y17iYwqG7tcFR39SDAqc9BkJb4SLD3muFXxzW2k6L
05vuuWciKh0R73mkszeK9P4Y/bz5RiNQl/Os/CRGK1w7t0UCAwEAAaOB5zCB5DAM
BgNVHRMBAf8EAjAAMDYGA1UdHwQvMC0wK6ApoCeGJWh0dHA6Ly9jcmwudGhhd3Rl
LmNvbS9UaGF3dGVTR0NDQS5jcmwwKAYDVR0lBCEwHwYIKwYBBQUHAwEGCCsGAQUF
BwMCBglghkgBhvhCBAEwcgYIKwYBBQUHAQEEZjBkMCIGCCsGAQUFBzABhhZodHRw
Oi8vb2NzcC50aGF3dGUuY29tMD4GCCsGAQUFBzAChjJodHRwOi8vd3d3LnRoYXd0
ZS5jb20vcmVwb3NpdG9yeS9UaGF3dGVfU0dDX0NBLmNydDANBgkqhkiG9w0BAQUF
AAOBgQCfQ89bxFApsb/isJr/aiEdLRLDLE5a+RLizrmCUi3nHX4adpaQedEkUjh5
u2ONgJd8IyAPkU0Wueru9G2Jysa9zCRo1kNbzipYvzwY4OA8Ys+WAi0oR1A04Se6
z5nRUP8pJcA2NhUzUnC+MY+f6H/nEQyNv4SgQhqAibAxWEEHXw==
-----END CERTIFICATE-----
subject=/C=US/ST=California/L=Mountain View/O=Google
Inc/CN=www<dot>google<dot>com
issuer=/C=ZA/O=Thawte Consulting (Pty) Ltd./CN=Thawte SGC CA
---
No client certificate CA names sent
---
SSL handshake has read 1772 bytes and written 313 bytes
---
New, TLSv1/SSLv3, Cipher is RC4-SHA
Server public key is 1024 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
SSL-Session:
    Protocol  : TLSv1
    Cipher    : RC4-SHA
    Session-ID:
E2CEF3FD72185DD712E49E49F7794445AA9B034B8E6D26023A02D41D1B3E6FD8
    Session-ID-ctx:
    Master-Key:
E35A311ADFB1BA4C53A84D836368316D2057ED794071E16602A6D5CE59E288C99437114AE4E809966D6082B2A826B9F6
    Key-Arg   : None
    Start Time: 1282152269
    Timeout   : 300 (sec)
    Verify return code: 20 (unable to get local issuer certificate)

----------------------------------------------------------

Server: SunOS rdcsol-10-01 5.10 Generic_142901-05 i86pc i386 i86pc
COmpiler used to compile php: cc: Sun C 5.10 SunOS_i386 2009/06/03

OpenSSL:
[r...@rdcsol-10-01]# /opt/csw/bin/openssl version -a
OpenSSL 0.9.8n 24 Mar 2010
built on: Thu Mar 25 21:12:32 CET 2010
platform: solaris-pentium_pro-cc
options:  bn(64,32) md2(int) rc4(ptr,char) des(ptr,cisc,16,long) idea(int)
blowfish(ptr)
compiler: cc -KPIC -DOPENSSL_PIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN
-DHAVE_DLFCN_H -fast -xarch=pentium_pro -O -Xa
OPENSSLDIR: "/opt/csw/ssl"

----------------------------------------------------------

Right now, I have compiled php against the OpenSSL packages from OpenCSW. I
have also tried compiling php against openssl-1.0.0 which I compiled myself
from source. This did not help anything as php was still having the exact
same ssl timeout errors.

I am really stumped here. Any help would be greatly appreciated.

Brent.

--- End Message ---
--- Begin Message ---
I'm trying to write a VERY simple script that does nothing but store all the 
submitted GET and POST vars in a string and echo it out.

$response = print_r($_REQUEST, true);
echo $response;

The problem is it only shows GET vars. I've tried $POST instead of $_REQUEST 
and it always gives an empty array. I've got it on two different servers, and 
we have three guys trying various methods of submitting forms to it, trying to 
eliminate all potential problems, like the possibility that the request might 
not actually have any POST vars. I think we've safely eliminated these 
possibilities.

Can anyone see a reason why the above should not see POST vars? Is there some 
security setting I don't know about?

--- End Message ---

Reply via email to