php-general Digest 23 Aug 2009 04:44:12 -0000 Issue 6300

Topics (messages 297082 through 297100):

Re: How to download and configure php mvc website locally
        297082 by: Shawn McKenzie

Re: preg_replace anything that isn't WORD
        297083 by: Jonathan Tapicer
        297087 by: Shawn McKenzie
        297090 by: Shawn McKenzie

Re: Rounding down?
        297084 by: Richard Heyes
        297095 by: Clancy

array() returns something weird
        297085 by: Szczepan Hołyszewski
        297086 by: Lars Torben Wilson
        297088 by: Szczepan Hołyszewski
        297089 by: Lars Torben Wilson
        297091 by: Ralph Deffke
        297092 by: Szczepan Hołyszewski
        297093 by: Lars Torben Wilson

Re: Invoking functions stored in a separate directory?
        297094 by: Clancy

Re: How do I extract link text from anchor tag as well as the URL from the 
"href" attribute
        297096 by: Raymond Irving

Re: Is there limitation for switch case: argument's value?
        297097 by: Keith
        297098 by: Keith
        297099 by: Keith
        297100 by: Lars Torben Wilson

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 ---
Sumit Sharma wrote:
> Hi all,
> The site I have download was developed using cake php. Now when trying to
> access the website it is showing a blank page. As Sudheer suggested I went
> to error log and noted down the errors there, which are as follows:
> 
> [Thu Aug 20 14:10:16 2009] [error] [client 127.0.0.1] File does not exist:
> F:/Rabin/xampp/htdocs/favicon.ico
> 
> I think there is no file called favicon.ico but how to create this file. Is
> this something related to cakephp configuration.
> 
> Regards,
>     Sumit
> 
> 
> 
> On Wed, Aug 19, 2009 at 8:25 PM, Sumit Sharma <sumitp...@gmail.com> wrote:
> 
>> Hi,
>> Please help as I have downloaded a php website for my client which is
>> developed using model view controller pattern. Now when I am accessing this
>> site locally it is not showing any thing. Please tell me the what's the
>> problem
>>
>> Thanks,
>>       Sumit Sharma
>>
> 

Have you installed the CakePHP framework in your include path?

-- 
Thanks!
-Shawn
http://www.spidean.com

--- End Message ---
--- Begin Message ---
Negating specific words with regexes isn't a good practice (see a deep
discussion here: http://www.perlmonks.org/?node_id=588315), in your
case I would resolve it like this:

<?php
$s = 'cats i saw a cat and a dog';
var_dump(preg_split('/(dog|cat)/', $s, -1, PREG_SPLIT_DELIM_CAPTURE |
PREG_SPLIT_NO_EMPTY));
?>

That will output:

array(5) {
  [0]=>
  string(3) "cat"
  [1]=>
  string(10) "s i saw a "
  [2]=>
  string(3) "cat"
  [3]=>
  string(7) " and a "
  [4]=>
  string(3) "dog"
}

Then you just have to go through the result array of preg_split and
concatenate every "cat" and "dog".

Regards,

Jonathan

On Sat, Aug 22, 2009 at 12:32 PM, דניאל דנון<danondan...@gmail.com> wrote:
> Lets assume I have the string "cats i  saw a cat and a dog"
> i want to strip everything except "cat" and "dog" so the result will be
> "catcatdog",
> using preg_replace.
>
>
> I've tried something like /[^(dog|cat)]+/ but no success
>
> What should I do?
>
> --
> Use ROT26 for best security
>

--- End Message ---
--- Begin Message ---
דניאל דנון wrote:
> Lets assume I have the string "cats i  saw a cat and a dog"
> i want to strip everything except "cat" and "dog" so the result will be
> "catcatdog",
> using preg_replace.
> 
> 
> I've tried something like /[^(dog|cat)]+/ but no success
> 
> What should I do?
> 

Capture everything but only replace the backreference for the words:

$r = preg_replace('#.*?(cat|dog).*?#', '\1', $s);

-- 
Thanks!
-Shawn
http://www.spidean.com

--- End Message ---
--- Begin Message ---
Didn't seem to make it the first time.

Shawn McKenzie wrote:
> דניאל דנון wrote:
>> Lets assume I have the string "cats i  saw a cat and a dog"
>> i want to strip everything except "cat" and "dog" so the result will be
>> "catcatdog",
>> using preg_replace.
>>
>>
>> I've tried something like /[^(dog|cat)]+/ but no success
>>
>> What should I do?
>>

Capture everything but only replace the backreference for the words:

$r = preg_replace('#.*?(cat|dog).*?#', '\1', $s);


-Shawn

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

> ...

A little modification:

<?php
    /**
    * Rounds down to the nearest 50
    */
    function myRound($val)
    {
        $units = intval(substr($val, -2));

        return intval(substr($val, 0, -2) . ($units >= 50 ? '50' : '00'));
    }

    echo myRound(449) . '<br />'; // 400
    echo myRound(450) . '<br />'; // 450
    echo myRound(356) . '<br />'; // 350
    echo myRound(79) . '<br />';  // 50
?>

PS I haven't checked if there's a PHP function for this.

-- 
Richard Heyes
HTML5 graphing: RGraph - www.rgraph.net (updated 8th August)
Lots of PHP and Javascript code - http://www.phpguru.org

--- End Message ---
--- Begin Message ---
On Sat, 22 Aug 2009 14:02:58 +0100, a...@ashleysheridan.co.uk (Ashley Sheridan) 
wrote:

>On Sat, 2009-08-22 at 13:00 +0100, Richard Heyes wrote:
>> Hi,
>> 
>> > Is there a way to round down to the nearest 50?
>> >
>> > Example: Any number between 400 and 449 I would 400 to be displayed; 450 
>> > to 499 would be 450; 500 to 549 would be 500, etc?
>> 
>> Off the top of my head: divide the number by 50, run floor() on the
>> result, then times it by 50.
>> 
>> 1. 449 / 50 = 9.whatever
>> 2. floor(9.whatever) = 9
>> 3. 9 * 50 = 450
>> 
>> -- 
>> Richard Heyes
>> HTML5 graphing: RGraph - www.rgraph.net (updated 8th August)
>> Lots of PHP and Javascript code - http://www.phpguru.org
>> 
>
>It should be round() and not floor().
>
>449 / 50 = 8.98
>floor(8.98) = 8
>8 * 50 = 400
>
>round(8.98) = 9
>9 * 50 = 450
>
Definitely floor or int, not round.

        Round 0.5-1.499 -> 1
        Floor 1.0-1.999 -> 1

And if you really want to be accurate  you should allow for decimal conversion 
errors in
any operation involving floating point numbers.  Otherwise you cannot rely on 
(say) 50 not
being represented as 49.9999999999, so that int or floor will give 49. In 
something like
this I usually add half of the precision I want to work to:

        eg: $answer = 50* (int) (($x +0.5)/50);

--- End Message ---
--- Begin Message ---
Hello!

I am almost certain I am hitting some kind of bug. All of a sudden, array() 
stops returning an empty array and starts returning something weird. The weird 
thing behaves as NULL in most circumstances (e.g. gettype() says NULL), 
except:

        $foo=array();      // <-- weird thing returned
        $foo[]="bar";

causes "Fatal error: [] operator not supported for strings", which is different 
from the regular behavior of:

        $foo=null;
        $foo[]="bar";      // <-- $foo simply becomes an array

The problem is not limited to one place in code, and indeed before the fatal 
caused by append-assignment I get several warnings like "array_diff_key(): 
Argument #1 is not an array", where the offending argument receives a result of 
array().

The effect is not random, i.e. it always breaks identically when the same 
script processes the same data. However I was so far unable to create a 
minimal test case that triggers the bug. My script is rather involved, and 
here are some things it uses:

 - Exceptions
 - DOM to-fro SimpleXML
 - lots of multi-level output buffering

Disabling Zend Optimizer doesn't help. Disabling Zend Memory Manager is 
apparently impossible. Memory usage is below 10MB out of 128MB limit.

Any similar experiences? Ideas what to check for? Workarounds?

From phpinfo():

PHP Version:
5.2.9 (can't easily upgrade - shared host)

System:
FreeBSD 7.1-RELEASE-p4 FreeBSD 7.1-RELEASE-p4 #0: Wed Apr 15 15:48:43 UTC 2009  
amd64

Configure Command:
'./configure' '--enable-bcmath' '--enable-calendar' '--enable-dbase' '--enable-
exif' '--enable-fastcgi' '--enable-force-cgi-redirect' '--enable-ftp' '--
enable-gd-native-ttf' '--enable-libxml' '--enable-magic-quotes' '--enable-
maintainer-zts' '--enable-mbstring' '--enable-pdo=shared' '--enable-safe-mode' 
'--enable-soap' '--enable-sockets' '--enable-ucd-snmp-hack' '--enable-wddx' 
'--enable-zend-multibyte' '--enable-zip' '--prefix=/usr' '--with-bz2' '--with-
curl=/opt/curlssl/' '--with-curlwrappers' '--with-freetype-dir=/usr/local' '--
with-gd' '--with-gettext' '--with-imap=/opt/php_with_imap_client/' '--with-
imap-ssl=/usr/local' '--with-jpeg-dir=/usr/local' '--with-libexpat-
dir=/usr/local' '--with-libxml-dir=/opt/xml2' '--with-libxml-dir=/opt/xml2/' 
'--with-mcrypt=/opt/libmcrypt/' '--with-mhash=/opt/mhash/' '--with-mime-magic' 
'--with-mysql=/usr/local' '--with-mysql-sock=/tmp/mysql.sock' '--with-
mysqli=/usr/local/bin/mysql_config' '--with-openssl=/usr/local' '--with-
openssl-dir=/usr/local' '--with-pdo-mysql=shared' '--with-pdo-sqlite=shared' 
'--with-pgsql=/usr/local' '--with-pic' '--with-png-dir=/usr/local' '--with-
pspell' '--with-snmp' '--with-sqlite=shared' '--with-tidy=/opt/tidy/' '--with-
ttf' '--with-xmlrpc' '--with-xpm-dir=/usr/local' '--with-xsl=/opt/xslt/' '--
with-zlib' '--with-zlib-dir=/usr'

Thanks in advance,
Szczepan Holyszewski

--- End Message ---
--- Begin Message ---
2009/8/22 Szczepan Hołyszewski <webmas...@strefarytmu.pl>:
> Hello!
>
> I am almost certain I am hitting some kind of bug. All of a sudden, array()
> stops returning an empty array and starts returning something weird. The weird
> thing behaves as NULL in most circumstances (e.g. gettype() says NULL),
> except:
>
>        $foo=array();      // <-- weird thing returned
>        $foo[]="bar";
>
> causes "Fatal error: [] operator not supported for strings", which is 
> different
> from the regular behavior of:

Hi there,

Without seeing the actual code, it's hard to say what the problem is.
However, I'd be pretty surprised if you've actually run into a bug in
PHP--I would first suspect a bug in your code. No offense
intended--that's just how it usually plays out. :)

What it looks like to me is that something is causing $foo to be a
string before the '$foo[] = "bar";' line is encountered. What do you
get if you put a gettype($foo); just before that line?

>        $foo=null;
>        $foo[]="bar";      // <-- $foo simply becomes an array
>
> The problem is not limited to one place in code, and indeed before the fatal
> caused by append-assignment I get several warnings like "array_diff_key():
> Argument #1 is not an array", where the offending argument receives a result 
> of
> array().

This would appear to support my suspicion, but try inserting the
gettype($foo) (or better, var_export($foo);) just before one of the
lines which triggers the error, and post the results.

Can you post the code in a .zip file or online somewhere? If not,
that's cool, but it will probably make it harder to help you track it
down if you can't.


Regards,

Torben

> The effect is not random, i.e. it always breaks identically when the same
> script processes the same data. However I was so far unable to create a
> minimal test case that triggers the bug. My script is rather involved, and
> here are some things it uses:
>
>  - Exceptions
>  - DOM to-fro SimpleXML
>  - lots of multi-level output buffering
>
> Disabling Zend Optimizer doesn't help. Disabling Zend Memory Manager is
> apparently impossible. Memory usage is below 10MB out of 128MB limit.
>
> Any similar experiences? Ideas what to check for? Workarounds?
>
> From phpinfo():
>
> PHP Version:
> 5.2.9 (can't easily upgrade - shared host)
>
> System:
> FreeBSD 7.1-RELEASE-p4 FreeBSD 7.1-RELEASE-p4 #0: Wed Apr 15 15:48:43 UTC 2009
> amd64
>
> Configure Command:
> './configure' '--enable-bcmath' '--enable-calendar' '--enable-dbase' 
> '--enable-
> exif' '--enable-fastcgi' '--enable-force-cgi-redirect' '--enable-ftp' '--
> enable-gd-native-ttf' '--enable-libxml' '--enable-magic-quotes' '--enable-
> maintainer-zts' '--enable-mbstring' '--enable-pdo=shared' '--enable-safe-mode'
> '--enable-soap' '--enable-sockets' '--enable-ucd-snmp-hack' '--enable-wddx'
> '--enable-zend-multibyte' '--enable-zip' '--prefix=/usr' '--with-bz2' '--with-
> curl=/opt/curlssl/' '--with-curlwrappers' '--with-freetype-dir=/usr/local' '--
> with-gd' '--with-gettext' '--with-imap=/opt/php_with_imap_client/' '--with-
> imap-ssl=/usr/local' '--with-jpeg-dir=/usr/local' '--with-libexpat-
> dir=/usr/local' '--with-libxml-dir=/opt/xml2' '--with-libxml-dir=/opt/xml2/'
> '--with-mcrypt=/opt/libmcrypt/' '--with-mhash=/opt/mhash/' '--with-mime-magic'
> '--with-mysql=/usr/local' '--with-mysql-sock=/tmp/mysql.sock' '--with-
> mysqli=/usr/local/bin/mysql_config' '--with-openssl=/usr/local' '--with-
> openssl-dir=/usr/local' '--with-pdo-mysql=shared' '--with-pdo-sqlite=shared'
> '--with-pgsql=/usr/local' '--with-pic' '--with-png-dir=/usr/local' '--with-
> pspell' '--with-snmp' '--with-sqlite=shared' '--with-tidy=/opt/tidy/' '--with-
> ttf' '--with-xmlrpc' '--with-xpm-dir=/usr/local' '--with-xsl=/opt/xslt/' '--
> with-zlib' '--with-zlib-dir=/usr'
>
> Thanks in advance,
> Szczepan Holyszewski
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
> What it looks like to me is that something is causing $foo to be a
> string before the '$foo[] = "bar";' line is encountered. What do you
> get if you put a gettype($foo); just before that line?
>
> >        $foo=null;
> >        $foo[]="bar";      // <-- $foo simply becomes an array

NULL. That is the problem. I _did_ put a gettype($foo) before the actual line.

OK, here are exact four lines of my code:

        $ret=array();
        foreach(self::$_allowed as $r => $a)
                if ($a)
                        $ret[]=$r;

As you can see, there is not a shred of a chance for $ret to become something 
other than empty array between initialization and the last line in the above 
snippet which causes the fatal errror. There's no __staticGet in 5.2.9, so 
self::$_allowed cannot have side effects.

Secondly, the above code starts failing after it has executed successfully 
dozens of times (and yes, the last line _does_ get executed; in fact self::
$_allowed contains configuration information that doesn't change at runtime).

Thirdly...

> > The problem is not limited to one place in code, and indeed before the
> > fatal caused by append-assignment I get several warnings like
> > "array_diff_key(): Argument #1 is not an array", where the offending
> > argument receives a result of array().
>
> This would appear to support my suspicion, but try inserting the
> gettype($foo) (or better, var_export($foo);) just before one of the
> lines which triggers the error, and post the results.

No, I don't think it supports your suspicion. Conversely, it indicates that 
once array() returns a strangelet, it starts returning strangelets all over 
the place. Initially it only triggers warnings but eventually one of the 
returned strangelets is used in a way that triggers a fatal error.

As per your request:

        //at the beginning of the script:

        $GLOBALS['offending_line_execution_count']=0;

        // /srv/home/[munged]/public_html/scripts/common.php line 161 and on
        // instrumented as per your request:

        public static function GetAllowed() {
        
                if (debug_mode()) echo 
++$GLOBALS['offending_line_execution_count']."<br/>";
                $ret=array();
                if (debug_mode()) echo var_export($ret)."<br/>";
                foreach(self::$_allowed as $r => $a)
                        if ($a)
                                $ret[]=$r;

                if (self::$_allowEmpty) $ret[]="";
                return $ret;
        }

Output tail:
-----------------------------------------------
28
array ( )
29
array ( )
30
array ( )
31
array ( )
32
array ( )

Warning: array_diff_key() [function.array-diff-key]: Argument #1 is not an 
array 
in /srv/home/u80959ue/public_html/v3/scripts/SimpliciText.php on line 350

Warning: Invalid argument supplied for foreach() in 
/srv/home/u80959ue/public_html/v3/scripts/SimpliciText.php on line 351

Warning: array_merge() [function.array-merge]: Argument #2 is not an array in 
/srv/home/u80959ue/public_html/v3/scripts/SimpliciText.php on line 357

Warning: Invalid argument supplied for foreach() in 
/srv/home/u80959ue/public_html/scripts/common.php on line 28

Warning: Invalid argument supplied for foreach() in 
/srv/home/u80959ue/public_html/scripts/common.php on line 28

Warning: Invalid argument supplied for foreach() in 
/srv/home/u80959ue/public_html/scripts/common.php on line 28
33
NULL

Fatal error: [] operator not supported for strings in 
/srv/home/u80959ue/public_html/scripts/common.php on line 168
--------------------------------------------------

The warnings come from other uses of array().

But wait! There is this invocation of debug_mode() between initialization of 
$ret var_export. Let's factor it out to be safe:

                $debugmode=debug_mode();
                if ($debugmode) echo 
++$GLOBALS['offending_line_execution_count']."<br/>";
                $ret=array();
                if ($debugmode) echo var_export($ret)."<br/>";

And now the output ends with:

------------------------------------
Warning: Invalid argument supplied for foreach() in 
/srv/home/u80959ue/public_html/scripts/common.php on line 28
33

Fatal error: [] operator not supported for strings in 
/srv/home/u80959ue/public_html/scripts/common.php on line 169
------------------------------------

No NULL after 33? What the heck is going on? Does array() now return something 
that var_exports to an empty string, or does it destroy local variables? Let's 
see:

                if ($debugmode) echo var_export($ret)."<br/>"; else echo 
"WTF?!?!?<br/>";

And the output:
------------------------------------
Warning: Invalid argument supplied for foreach() in 
/srv/home/u80959ue/public_html/scripts/common.php on line 28
33
WTF?!?!?

Fatal error: [] operator not supported for strings in 
/srv/home/u80959ue/public_html/scripts/common.php on line 169
---------------------------------------

Indeed, the use of array(), once it starts misbehaving, wreaks havoc in the 
local scope (possibly including the variable to which its result is assigned).

> Can you post the code in a .zip file or online somewhere?

Unfortunately not.

Szczepan Holyszewski

--- End Message ---
--- Begin Message ---
2009/8/22 Szczepan Hołyszewski <webmas...@strefarytmu.pl>:
>> What it looks like to me is that something is causing $foo to be a
>> string before the '$foo[] = "bar";' line is encountered. What do you
>> get if you put a gettype($foo); just before that line?
>>
>> >        $foo=null;
>> >        $foo[]="bar";      // <-- $foo simply becomes an array
>
> NULL. That is the problem. I _did_ put a gettype($foo) before the actual line.
>
> OK, here are exact four lines of my code:
>
>        $ret=array();
>        foreach(self::$_allowed as $r => $a)
>                if ($a)
>                        $ret[]=$r;
>
> As you can see, there is not a shred of a chance for $ret to become something
> other than empty array between initialization and the last line in the above
> snippet which causes the fatal errror. There's no __staticGet in 5.2.9, so
> self::$_allowed cannot have side effects.
>
> Secondly, the above code starts failing after it has executed successfully
> dozens of times (and yes, the last line _does_ get executed; in fact self::
> $_allowed contains configuration information that doesn't change at runtime).
>
> Thirdly...
>
>> > The problem is not limited to one place in code, and indeed before the
>> > fatal caused by append-assignment I get several warnings like
>> > "array_diff_key(): Argument #1 is not an array", where the offending
>> > argument receives a result of array().
>>
>> This would appear to support my suspicion, but try inserting the
>> gettype($foo) (or better, var_export($foo);) just before one of the
>> lines which triggers the error, and post the results.
>
> No, I don't think it supports your suspicion. Conversely, it indicates that
> once array() returns a strangelet, it starts returning strangelets all over
> the place. Initially it only triggers warnings but eventually one of the
> returned strangelets is used in a way that triggers a fatal error.
>
> As per your request:
>
>        //at the beginning of the script:
>
>        $GLOBALS['offending_line_execution_count']=0;
>
>        // /srv/home/[munged]/public_html/scripts/common.php line 161 and on
>        // instrumented as per your request:
>
>        public static function GetAllowed() {
>
>                if (debug_mode()) echo 
> ++$GLOBALS['offending_line_execution_count']."<br/>";
>                $ret=array();
>                if (debug_mode()) echo var_export($ret)."<br/>";
>                foreach(self::$_allowed as $r => $a)
>                        if ($a)
>                                $ret[]=$r;
>
>                if (self::$_allowEmpty) $ret[]="";
>                return $ret;
>        }
>
> Output tail:
> -----------------------------------------------
> 28
> array ( )
> 29
> array ( )
> 30
> array ( )
> 31
> array ( )
> 32
> array ( )
>
> Warning: array_diff_key() [function.array-diff-key]: Argument #1 is not an 
> array
> in /srv/home/u80959ue/public_html/v3/scripts/SimpliciText.php on line 350
>
> Warning: Invalid argument supplied for foreach() in
> /srv/home/u80959ue/public_html/v3/scripts/SimpliciText.php on line 351
>
> Warning: array_merge() [function.array-merge]: Argument #2 is not an array in
> /srv/home/u80959ue/public_html/v3/scripts/SimpliciText.php on line 357
>
> Warning: Invalid argument supplied for foreach() in
> /srv/home/u80959ue/public_html/scripts/common.php on line 28
>
> Warning: Invalid argument supplied for foreach() in
> /srv/home/u80959ue/public_html/scripts/common.php on line 28
>
> Warning: Invalid argument supplied for foreach() in
> /srv/home/u80959ue/public_html/scripts/common.php on line 28
> 33
> NULL
>
> Fatal error: [] operator not supported for strings in
> /srv/home/u80959ue/public_html/scripts/common.php on line 168
> --------------------------------------------------
>
> The warnings come from other uses of array().
>
> But wait! There is this invocation of debug_mode() between initialization of
> $ret var_export. Let's factor it out to be safe:
>
>                $debugmode=debug_mode();
>                if ($debugmode) echo 
> ++$GLOBALS['offending_line_execution_count']."<br/>";
>                $ret=array();
>                if ($debugmode) echo var_export($ret)."<br/>";
>
> And now the output ends with:
>
> ------------------------------------
> Warning: Invalid argument supplied for foreach() in
> /srv/home/u80959ue/public_html/scripts/common.php on line 28
> 33
>
> Fatal error: [] operator not supported for strings in
> /srv/home/u80959ue/public_html/scripts/common.php on line 169
> ------------------------------------
>
> No NULL after 33? What the heck is going on? Does array() now return something
> that var_exports to an empty string, or does it destroy local variables? Let's
> see:
>
>                if ($debugmode) echo var_export($ret)."<br/>"; else echo 
> "WTF?!?!?<br/>";
>
> And the output:
> ------------------------------------
> Warning: Invalid argument supplied for foreach() in
> /srv/home/u80959ue/public_html/scripts/common.php on line 28
> 33
> WTF?!?!?
>
> Fatal error: [] operator not supported for strings in
> /srv/home/u80959ue/public_html/scripts/common.php on line 169
> ---------------------------------------
>
> Indeed, the use of array(), once it starts misbehaving, wreaks havoc in the
> local scope (possibly including the variable to which its result is assigned).
>
>> Can you post the code in a .zip file or online somewhere?
>
> Unfortunately not.
>
> Szczepan Holyszewski

Hm. . .it does look odd. Searching the bugs database at
http://bugs.php.net does turn up one other report (at
http://bugs.php.net/bug.php?id=47870 ) of array() returning NULL in
certain hard-to-duplicate circumstances on FreeBSD, although it's a
different version of FreeBSD and is reported against
5.3CVS-2009-04-01. There are differences but the similarities are
suspicious. That particular bug was fixed but if this does in fact
turn out to be a bug in PHP then the ability to test other versions
would be very useful. Too bad about the shared host. I know how hard
it can be to get them to install other versions, even if just for
testing.

I don't suppose you have a development environment on another machine
where you can test another version of PHP? If not, it's going to be
slightly difficult to pin down.

It may be worth it for you to add a comment to the above bug report.
The current 5.2 is only at 5.2.10 so the version you're using isn't
very old, and a fix for this problem is not specifically mentioned in
the PHP 5.2.10 changelog.


Good luck!

Torben

--- End Message ---
--- Begin Message ---
well, when I saw ur post I got immediately the thought I would bed it has to
do with some stuff of $this or self.

I did play arround a bit with class creation the last days and yes, with
using self parent and $this I did put the HTTPPD in unstable and sometimes
it died without beeing able to send any error.

well this doesn't help very mutch.

I have two point:

(1)ur code is ( sorry ) lazy written, invest the brackets !! ur code writing
is predestinated for that type of error. shooting variable types arround by
pulling out of foreach loops,  if's, .... is typical.

(2) using static variables are known for type missmatch errors just anything
has acces to them even if the containing class is not instantinated. many
dirty things can happen unless of corse they are not private.

further sugestions: check if you work on ur arrays with functions returning
array on success but false on fail or something like that. also a typical
source for that type of error

are u using magic __set ? I ran into a type change as well with it

good luck

ralph_def...@yahoo.de


"Szczepan Holyszewski" <webmas...@strefarytmu.pl> wrote in message
news:200908222152.55846.webmas...@strefarytmu.pl...
> > What it looks like to me is that something is causing $foo to be a
> > string before the '$foo[] = "bar";' line is encountered. What do you
> > get if you put a gettype($foo); just before that line?
> >
> > >        $foo=null;
> > >        $foo[]="bar";      // <-- $foo simply becomes an array
>
> NULL. That is the problem. I _did_ put a gettype($foo) before the actual
line.
>
> OK, here are exact four lines of my code:
>
> $ret=array();
> foreach(self::$_allowed as $r => $a)
> if ($a)
> $ret[]=$r;
>
> As you can see, there is not a shred of a chance for $ret to become
something
> other than empty array between initialization and the last line in the
above
> snippet which causes the fatal errror. There's no __staticGet in 5.2.9, so
> self::$_allowed cannot have side effects.
>
> Secondly, the above code starts failing after it has executed successfully
> dozens of times (and yes, the last line _does_ get executed; in fact
self::
> $_allowed contains configuration information that doesn't change at
runtime).
>
> Thirdly...
>
> > > The problem is not limited to one place in code, and indeed before the
> > > fatal caused by append-assignment I get several warnings like
> > > "array_diff_key(): Argument #1 is not an array", where the offending
> > > argument receives a result of array().
> >
> > This would appear to support my suspicion, but try inserting the
> > gettype($foo) (or better, var_export($foo);) just before one of the
> > lines which triggers the error, and post the results.
>
> No, I don't think it supports your suspicion. Conversely, it indicates
that
> once array() returns a strangelet, it starts returning strangelets all
over
> the place. Initially it only triggers warnings but eventually one of the
> returned strangelets is used in a way that triggers a fatal error.
>
> As per your request:
>
> //at the beginning of the script:
>
> $GLOBALS['offending_line_execution_count']=0;
>
> // /srv/home/[munged]/public_html/scripts/common.php line 161 and on
> // instrumented as per your request:
>
> public static function GetAllowed() {
>
> if (debug_mode()) echo
++$GLOBALS['offending_line_execution_count']."<br/>";
> $ret=array();
> if (debug_mode()) echo var_export($ret)."<br/>";
> foreach(self::$_allowed as $r => $a)
> if ($a)
> $ret[]=$r;
>
> if (self::$_allowEmpty) $ret[]="";
> return $ret;
> }
>
> Output tail:
> -----------------------------------------------
> 28
> array ( )
> 29
> array ( )
> 30
> array ( )
> 31
> array ( )
> 32
> array ( )
>
> Warning: array_diff_key() [function.array-diff-key]: Argument #1 is not an
array
> in /srv/home/u80959ue/public_html/v3/scripts/SimpliciText.php on line 350
>
> Warning: Invalid argument supplied for foreach() in
> /srv/home/u80959ue/public_html/v3/scripts/SimpliciText.php on line 351
>
> Warning: array_merge() [function.array-merge]: Argument #2 is not an array
in
> /srv/home/u80959ue/public_html/v3/scripts/SimpliciText.php on line 357
>
> Warning: Invalid argument supplied for foreach() in
> /srv/home/u80959ue/public_html/scripts/common.php on line 28
>
> Warning: Invalid argument supplied for foreach() in
> /srv/home/u80959ue/public_html/scripts/common.php on line 28
>
> Warning: Invalid argument supplied for foreach() in
> /srv/home/u80959ue/public_html/scripts/common.php on line 28
> 33
> NULL
>
> Fatal error: [] operator not supported for strings in
> /srv/home/u80959ue/public_html/scripts/common.php on line 168
> --------------------------------------------------
>
> The warnings come from other uses of array().
>
> But wait! There is this invocation of debug_mode() between initialization
of
> $ret var_export. Let's factor it out to be safe:
>
> $debugmode=debug_mode();
> if ($debugmode) echo ++$GLOBALS['offending_line_execution_count']."<br/>";
> $ret=array();
> if ($debugmode) echo var_export($ret)."<br/>";
>
> And now the output ends with:
>
> ------------------------------------
> Warning: Invalid argument supplied for foreach() in
> /srv/home/u80959ue/public_html/scripts/common.php on line 28
> 33
>
> Fatal error: [] operator not supported for strings in
> /srv/home/u80959ue/public_html/scripts/common.php on line 169
> ------------------------------------
>
> No NULL after 33? What the heck is going on? Does array() now return
something
> that var_exports to an empty string, or does it destroy local variables?
Let's
> see:
>
> if ($debugmode) echo var_export($ret)."<br/>"; else echo "WTF?!?!?<br/>";
>
> And the output:
> ------------------------------------
> Warning: Invalid argument supplied for foreach() in
> /srv/home/u80959ue/public_html/scripts/common.php on line 28
> 33
> WTF?!?!?
>
> Fatal error: [] operator not supported for strings in
> /srv/home/u80959ue/public_html/scripts/common.php on line 169
> ---------------------------------------
>
> Indeed, the use of array(), once it starts misbehaving, wreaks havoc in
the
> local scope (possibly including the variable to which its result is
assigned).
>
> > Can you post the code in a .zip file or online somewhere?
>
> Unfortunately not.
>
> Szczepan Holyszewski



--- End Message ---
--- Begin Message ---
> Hm. . .it does look odd. Searching the bugs database at
> http://bugs.php.net does turn up one other report (at
> http://bugs.php.net/bug.php?id=47870 ) of array() returning NULL in
> certain hard-to-duplicate circumstances on FreeBSD,

Yes, I found it even before posting here, but I wasn't sure whether to file a 
new report or comment under this one. If your intuition is that these bugs are 
related, then I will do the latter. Thank you for your attention.

> I don't suppose you have a development environment on another
> machine where you can test another version of PHP?

Assuming you mean a FreeBSD environment, nope :( but I will try on Linux 
tomorrow.

Regards,
Szczepan Holyszewski


--- End Message ---
--- Begin Message ---
2009/8/22 Szczepan Hołyszewski <webmas...@strefarytmu.pl>:
>> Hm. . .it does look odd. Searching the bugs database at
>> http://bugs.php.net does turn up one other report (at
>> http://bugs.php.net/bug.php?id=47870 ) of array() returning NULL in
>> certain hard-to-duplicate circumstances on FreeBSD,
>
> Yes, I found it even before posting here, but I wasn't sure whether to file a
> new report or comment under this one. If your intuition is that these bugs are
> related, then I will do the latter. Thank you for your attention.

Well, the only things I'm basing my suspicion on are the nature of the
problem, the OS similarity and the fact that it seems to be difficult
to reproduce the problem reliably. The major problem with this guess
is that the original bug report does state that the bug did not show
up under 5.2.

>> I don't suppose you have a development environment on another
>> machine where you can test another version of PHP?
>
> Assuming you mean a FreeBSD environment, nope :( but I will try on Linux
> tomorrow.

OK. I do think (as I'm sure you know) that the best test would be in a
matching environment (since the result was reported to be different
under Linux for that bug), but of course that's not always realistic.

> Regards,
> Szczepan Holyszewski

I hope your problem can be resolved. If it does turn out to be a bug
in PHP I hope that will be enough to convince your host to upgrade.


Regards,

Torben

--- End Message ---
--- Begin Message ---
On Sat, 22 Aug 2009 20:37:17 +0930, robl...@aapt.net.au (David Robley) wrote:

>Clancy wrote:
>
>> $ok = include (HOST_PATH.'/Halla.php');
>
>Because you are assigning the result of the include to a variable. Try 
>
>include (HOST_PATH.'/Halla.php');
>
>and it will work as you expect. And similarly for 
>
>define ('HOST_PATH','../Engine');

Thanks. But no; that's not the answer.  'Include', like any other function, 
returns a
result; true if the operation was successful, and false if it failed. I was 
using this to
verify that the 'include' operation had been successful.

The more I thought about it last night, the more dissatisfied I became with the 
notions
that 'include' could work differently in different circumstances, and also that 
defining a
path could alter the way it worked.

I did some more tests this morning, and eventually established that my 
confusion was the
result of two different effects.

The first was that I find the PHP syntax rather picky,  and I rely on error 
messages to
alert me to my frequent errors, but apparently all error messages are turned 
off on the
remote system, and if anything is wrong all I get is a blank screen.

The second is that although I use Dreamweaver as an editor, and it has 
moderately good
colour coding which indicate most errors, I am partially red green colour blind 
and tend
not to notice the erroneous colours.

I repeated my tests this morning and eventually managed to establish that

        i. there is no difference in the behaviour of include between the local 
and remote
systems, and

        ii. contrary to Arno's advice, include ../Engine/Main_prog.php; works 
just the
same as include ENGINEPATH."Main_prog.php";

So now I can get on with uploading my program!

Thanks,

--- End Message ---
--- Begin Message ---
Hello,

You might also want to try using the Raxan framework:

require_once 'raxan/pdi/gateway.php';

$page = new RichWebPage('page.html');
echo $page['a']->text(); // this will get the text betwen the a tag
 
To get the image element use:

$elm = $page['a img']->node(0);

You can download Raxan here:
http://raxanpdi.com/downloads.html

__
Raymond Irving

--- On Sat, 8/22/09, Manuel Lemos <mle...@acm.org> wrote:

From: Manuel Lemos <mle...@acm.org>
Subject: [PHP] Re: How do I extract link text from anchor tag as well as the 
URL from the "href" attribute
To: "chrysanhy" <phpli...@hyphusonline.com>
Cc: php-gene...@lists.php.net
Date: Saturday, August 22, 2009, 1:07 AM

Hello,

on 08/16/2009 04:33 AM chrysanhy said the following:
> I have the following code to extract the URLs from the anchor tags of an
> HTML page:
> 
> $html = new DOMDocument();
> $htmlpage->loadHtmlFile($location);
> $xpath = new DOMXPath($htmlpage);
> $links = $xpath->query( '//a' );
> foreach ($links as $link)
> { $int_url_list[$i++] = $link->getAttribute( 'href' ) . "\n"; }
> 
> If I have a link <a href="http://X.com";>YYYY</a>, how do I extract the
> corresponding YYYY which is displayed to the user as the text of the link
> (if it's an image tag, I would like a DOMElement for that).
> Thanks

You may want to try this HTML parser class that comes with filter class
and an example script named test_get_html_links.php  that does exactly
what you ask.

http://www.phpclasses.org/secure-html-filter

-- 

Regards,
Manuel Lemos

Find and post PHP jobs
http://www.phpclasses.org/jobs/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--- End Message ---
--- Begin Message ---
Thanks! Torben.
I got the point now and it works! :-)
I'm doing this because the statements of each cases is quite long, and I wish to have minimum coding without repetition.


"Lars Torben Wilson" <larstor...@gmail.com> wrote in message news:36d4833b0908202323p3c858b5fn6a1d6775aa7f8...@mail.gmail.com...
2009/8/20 Keith <survivor_...@hotmail.com>:
Hi,
I encounter a funny limitation here with switch case as below:
The value for $sum is worked as expected for 1 to 8, but not for 0.
When the $sum=0, the first case will be return, which is "sum=8".
Is there any limitation / rules for switch case? Thanks for advice!

Keith

Hi Keith,

Try replacing 'switch($sum)' with 'switch(true)'.

Note that unless you have very good reasons for using a switch
statement like this, and know exactly why you're doing it, it's often
better just to use it in the normal fashion. i.e.:

      switch ($sum)
       {
       case 8:
           break;
       case 7:
       case 6:
           break;
       case 2:
       case 1:
           break;
       case 0:
           break;
default:
           break;
       }

Some people like the syntax you've presented but honestly, there's
usually a better way to do it.

This is also somewhat faster too, although you may only notice the
difference in very tight loops where you're counting every nanosecond.


Regards,

Torben

$sum=0;
switch($sum)
{
  case ($sum==8):
  echo "sum=8";
  break;
      case ($sum==7 || $sum==6):
      echo "sum=7 or 6";
      break;
  case ($sum==2 || $sum==1):
  echo "sum=2 or 1";
  break;
      case 0:
      echo "sum=0";
      break;
  default:
  echo "sum=3/4/5";
  break;
}
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--- End Message ---
--- Begin Message ---
Thanks! Adam.
It works now!
Actually I thought that switch block is compatible with if/elseif/else block but more efficient if the cases is >3. Because I like to have short coding without repetition, so I group the similar cases together. Thanks for your explanation! I know where is my mistake already and I've learnt a lesson today!

"Adam Randall" <randa...@gmail.com> wrote in message news:b6d6f8360908202319n240bba5al6c02edb6e890b...@mail.gmail.com...
I've never understood why people use switch statements like this as in
reality you are using it more like an if/else block, but anyway.

The reason why your code is not working is that you are passing into
the switch the value of 0, or false, which means that when any of
those $sum == N conditionals comes up as false (say $sum == 8 ), then
that is what is returned because they match up. In PHP's eyes, 0 ==
false in switch statements.

To fix your code, change the switch( $sum ) to switch( true ):

switch( true )
{
case ($sum == 8):
echo "sum=8\n";
break;
case ($sum == 7 || $sum == 6):
echo "sum=7 or 6\n";
break;
case ($sum == 2 || $sum == 1):
echo "sum=2 or 1\n";
break;
case ($sum == 0):
echo "sum=0\n";
break;
default:
echo "sum=3/4/5\n";
break;
}

Or, write your switch like this:

switch( $sum )
{
case 8:
echo "sum=8\n";
break;
case 6:
case 7:
echo "sum=7 or 6\n";
break;
case 1:
case 2:
echo "sum=2 or 1\n";
break;
case 0:
echo "sum=0\n";
break;
default:
echo "sum=3/4/5\n";
break;
}

Regards,

Adam.

On Thu, Aug 20, 2009 at 8:40 PM, Keith<survivor_...@hotmail.com> wrote:
Hi,
I encounter a funny limitation here with switch case as below:
The value for $sum is worked as expected for 1 to 8, but not for 0.
When the $sum=0, the first case will be return, which is "sum=8".
Is there any limitation / rules for switch case? Thanks for advice!

Keith

$sum=0;
switch($sum)
{
  case ($sum==8):
  echo "sum=8";
  break;
      case ($sum==7 || $sum==6):
      echo "sum=7 or 6";
      break;
  case ($sum==2 || $sum==1):
  echo "sum=2 or 1";
  break;
      case 0:
      echo "sum=0";
      break;
  default:
  echo "sum=3/4/5";
  break;
}
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





--
Adam Randall
http://www.xaren.net
AIM: blitz574


--- End Message ---
--- Begin Message --- Hahaha! Actually this is my first time coding, so I still adapting the correct way to do it. FYI, for the sake of minimizing the coding and viewing space occupied of the code, I even replace the switch block with array if the cases are just merely selecting pool of variables/categories/parameters!
I'm still learning the best practice for coding. :-)

""Daevid Vincent"" <dae...@daevid.com> wrote in message news:fef58898dc3544e3872458cd64661...@mascorp.com...
Whoa! I didn't even know you could use a switch statement like that. In 20
years of coding, I've never ever used a switch like that first "if/else"
style. PHP never ceases to amaze me in it's flexibility (and ability to
shoot yourself in the foot ;-p )

And remember, all your base are belong to Adam.

-----Original Message-----
From: Adam Randall [mailto:randa...@gmail.com]
Sent: Thursday, August 20, 2009 11:20 PM
To: Keith
Cc: php-gene...@lists.php.net
Subject: Re: [PHP] Is there limitation for switch case:
argument's value?

I've never understood why people use switch statements like this as in
reality you are using it more like an if/else block, but anyway.

The reason why your code is not working is that you are passing into
the switch the value of 0, or false, which means that when any of
those $sum == N conditionals comes up as false (say $sum == 8 ), then
that is what is returned because they match up. In PHP's eyes, 0 ==
false in switch statements.

To fix your code, change the switch( $sum ) to switch( true ):

switch( true )
{
case ($sum == 8):
echo "sum=8\n";
break;
case ($sum == 7 || $sum == 6):
echo "sum=7 or 6\n";
break;
case ($sum == 2 || $sum == 1):
echo "sum=2 or 1\n";
break;
case ($sum == 0):
echo "sum=0\n";
break;
default:
echo "sum=3/4/5\n";
break;
}

Or, write your switch like this:

switch( $sum )
{
case 8:
echo "sum=8\n";
break;
case 6:
case 7:
echo "sum=7 or 6\n";
break;
case 1:
case 2:
echo "sum=2 or 1\n";
break;
case 0:
echo "sum=0\n";
break;
default:
echo "sum=3/4/5\n";
break;
}

Regards,

Adam.

On Thu, Aug 20, 2009 at 8:40 PM,
Keith<survivor_...@hotmail.com> wrote:
> Hi,
> I encounter a funny limitation here with switch case as below:
> The value for $sum is worked as expected for 1 to 8, but not for 0.
> When the $sum=0, the first case will be return, which is "sum=8".
> Is there any limitation / rules for switch case? Thanks for advice!
>
> Keith
>
> $sum=0;
> switch($sum)
> {
>   case ($sum==8):
>   echo "sum=8";
>   break;
>       case ($sum==7 || $sum==6):
>       echo "sum=7 or 6";
>       break;
>   case ($sum==2 || $sum==1):
>   echo "sum=2 or 1";
>   break;
>       case 0:
>       echo "sum=0";
>       break;
>   default:
>   echo "sum=3/4/5";
>   break;
> }
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



--
Adam Randall
http://www.xaren.net
AIM: blitz574

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--- End Message ---
--- Begin Message ---
2009/8/22 Keith <survivor_...@hotmail.com>:
> Thanks! Torben.
> I got the point now and it works! :-)
> I'm doing this because the statements of each cases is quite long, and I
> wish to have minimum coding without repetition.

Hi Keith,

Glad it works! I'm not sure how inverting the case statement helps you
minimize the code in each case. As both I and Adam showed, you can do
the same thing more efficiently (and IMHO much more readably) like
this:

switch ($sum)
{
    case 8:

       break;
    case 7:
    case 6:
       break;
    case 2:
    case 1:
       break;
    case 0:
       break;
    default:
       break;
}

> "Lars Torben Wilson" <larstor...@gmail.com> wrote in message
> news:36d4833b0908202323p3c858b5fn6a1d6775aa7f8...@mail.gmail.com...
>>
>> 2009/8/20 Keith <survivor_...@hotmail.com>:
>>>
>>> Hi,
>>> I encounter a funny limitation here with switch case as below:
>>> The value for $sum is worked as expected for 1 to 8, but not for 0.
>>> When the $sum=0, the first case will be return, which is "sum=8".
>>> Is there any limitation / rules for switch case? Thanks for advice!
>>>
>>> Keith
>>
>> Hi Keith,
>>
>> Try replacing 'switch($sum)' with 'switch(true)'.
>>
>> Note that unless you have very good reasons for using a switch
>> statement like this, and know exactly why you're doing it, it's often
>> better just to use it in the normal fashion. i.e.:
>>
>>      switch ($sum)
>>       {
>>       case 8:
>>           break;
>>       case 7:
>>       case 6:
>>           break;
>>       case 2:
>>       case 1:
>>           break;
>>       case 0:
>>           break;
>> default:
>>           break;
>>       }
>>
>> Some people like the syntax you've presented but honestly, there's
>> usually a better way to do it.
>>
>> This is also somewhat faster too, although you may only notice the
>> difference in very tight loops where you're counting every nanosecond.
>>
>>
>> Regards,
>>
>> Torben
>>
>>> $sum=0;
>>> switch($sum)
>>> {
>>>  case ($sum==8):
>>>  echo "sum=8";
>>>  break;
>>>      case ($sum==7 || $sum==6):
>>>      echo "sum=7 or 6";
>>>      break;
>>>  case ($sum==2 || $sum==1):
>>>  echo "sum=2 or 1";
>>>  break;
>>>      case 0:
>>>      echo "sum=0";
>>>      break;
>>>  default:
>>>  echo "sum=3/4/5";
>>>  break;
>>> }
>>> --
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>
>>>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---

Reply via email to