Laruence | 2 Nov 2011 09:55
Picon
Gravatar

Re: [PHP-DEV] Re: [PATCH] Notice on array to string convertion

On Mon, Oct 31, 2011 at 10:55 AM, Stas Malyshev <smalyshev <at> sugarcrm.com> wrote:
> Hi!
>
>> Hi:
>>   like the following script:
>>   <?php
>> $str = (string)array();
>> echo $str;
>>
>>    it is obviously intentionally convert a array to string ,  but the
>> warning is coming:
>
> I think it's the correct way to react for PHP. This code is an extremely
> convoluted way to write "echo 'Array';" and as such doesn't seem to do
> anything useful. I have yet to see one single instance where converting
> array to string made any sense. Of course,
>
> As for the warning in 60174, it seems to be a bug indeed - the code there
> has no business converting any arrays to strings and in general the engine
> shouldn't apply make_printable_zval to arrays knowingly - there's no useful
> result that can come from that as far as I can see. So if you know more of
> such cases lease point them out and they should be fixed.
 #60198	Array to string notice from array functions

Some of the array_* functions that compare elements in multiple arrays do so by
(string)$elem1 === (string)$elem2.

If $elem1 or $elem2 is an array, then the array to string notice is thrown.

https://bugs.php.net/bug.php?id=60198
(Continue reading)

Etienne Kneuss | 2 Nov 2011 11:41
Picon
Gravatar

Re: [PHP-DEV] Re: [PATCH] Notice on array to string convertion

Hi,

On Wed, Nov 2, 2011 at 09:55, Laruence <laruence <at> php.net> wrote:
> On Mon, Oct 31, 2011 at 10:55 AM, Stas Malyshev <smalyshev <at> sugarcrm.com> wrote:
>> Hi!
>>
>>> Hi:
>>>   like the following script:
>>>   <?php
>>> $str = (string)array();
>>> echo $str;
>>>
>>>    it is obviously intentionally convert a array to string ,  but the
>>> warning is coming:
>>
>> I think it's the correct way to react for PHP. This code is an extremely
>> convoluted way to write "echo 'Array';" and as such doesn't seem to do
>> anything useful. I have yet to see one single instance where converting
>> array to string made any sense. Of course,
>>
>> As for the warning in 60174, it seems to be a bug indeed - the code there
>> has no business converting any arrays to strings and in general the engine
>> shouldn't apply make_printable_zval to arrays knowingly - there's no useful
>> result that can come from that as far as I can see. So if you know more of
>> such cases lease point them out and they should be fixed.
>  #60198 Array to string notice from array functions
>
> Some of the array_* functions that compare elements in multiple arrays do so by
> (string)$elem1 === (string)$elem2.
>
(Continue reading)

Stas Malyshev | 2 Nov 2011 16:04
Favicon
Gravatar

Re: [PHP-DEV] Re: [PATCH] Notice on array to string convertion

Hi!

> In such cases, the notice actually seems fine to me. This is typically
> the cases where you want to inform the user that he probably did
> something wrong...

In this specific case, I would say notice is not needed - it is obvious 
that a string is not equal to any array, so there's no need to convert 
anything if one of the variables is array and another is not - just 
consider them not equal.
-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

--

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Etienne Kneuss | 2 Nov 2011 16:39
Picon
Gravatar

Re: [PHP-DEV] Re: [PATCH] Notice on array to string convertion

On Nov 2, 2011 4:05 PM, "Stas Malyshev" <smalyshev <at> sugarcrm.com> wrote:
>
> Hi!
>
>
>> In such cases, the notice actually seems fine to me. This is typically
>> the cases where you want to inform the user that he probably did
>> something wrong...
>
>
> In this specific case, I would say notice is not needed - it is obvious
that a string is not equal to any array, so there's no need to convert
anything if one of the variables is array and another is not - just
consider them not equal.

What about array_diff(array("Array"), array(array()))? To me the sole act
of having an array in it is an almost sure indication that the code is
wrong somewhere... IMO it deserves a notice.

>
> --
> Stanislav Malyshev, Software Architect
> SugarCRM: http://www.sugarcrm.com/
> (408)454-6900 ext. 227
Stas Malyshev | 2 Nov 2011 17:27
Favicon
Gravatar

Re: [PHP-DEV] Re: [PATCH] Notice on array to string convertion

Hi!

> What about array_diff(array("Array"), array(array()))? To me the sole
> act of having an array in it is an almost sure indication that the code
> is wrong somewhere... IMO it deserves a notice.

That one would have the arrays different. Having multi-dimensonal arrays 
is not an error, comparing arrays of different structure is not an error 
either. Consider expression: "a" == array(). Is it an error? No, it's 
just a false expression. In the same way all comparisons where you 
compare string to array should just say it's not equal, since we know 
they're not equal.

--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

--

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Etienne Kneuss | 2 Nov 2011 17:43
Picon
Gravatar

Re: [PHP-DEV] Re: [PATCH] Notice on array to string convertion

Hi,

On Wed, Nov 2, 2011 at 17:27, Stas Malyshev <smalyshev <at> sugarcrm.com> wrote:
> Hi!
>
>> What about array_diff(array("Array"), array(array()))? To me the sole
>> act of having an array in it is an almost sure indication that the code
>> is wrong somewhere... IMO it deserves a notice.
>
> That one would have the arrays different.

Well, they are not different elements w.r.t array_diff, so it does
return array() since (string)"Array" === (string)array().

My point is: there is an implicit usage of string representations  in
those functions due to the cast. And it can yield various unexpected
results.

Another example is:

array_intersect(array(array(1)), array(array(2))) === array(array(1)).
Even though array(1) != array(2).

To me it falls exactly within what the patch tries to achieve: report
potential unintentional misuses of arrays.

> Having multi-dimensonal arrays is
> not an error, comparing arrays of different structure is not an error
> either. Consider expression: "a" == array(). Is it an error? No, it's just a
> false expression.
(Continue reading)

Patrick ALLAERT | 2 Nov 2011 21:22
Picon
Gravatar

Re: [PHP-DEV] Re: [PATCH] Notice on array to string convertion

2011/11/2 Etienne Kneuss <colder <at> php.net>:
> Hi,
>
> On Wed, Nov 2, 2011 at 17:27, Stas Malyshev <smalyshev <at> sugarcrm.com> wrote:
>> Hi!
>>
>>> What about array_diff(array("Array"), array(array()))? To me the sole
>>> act of having an array in it is an almost sure indication that the code
>>> is wrong somewhere... IMO it deserves a notice.
>>
>> That one would have the arrays different.
>
> Well, they are not different elements w.r.t array_diff, so it does
> return array() since (string)"Array" === (string)array().
>
> My point is: there is an implicit usage of string representations  in
> those functions due to the cast. And it can yield various unexpected
> results.
>
> Another example is:
>
> array_intersect(array(array(1)), array(array(2))) === array(array(1)).
> Even though array(1) != array(2).
>
> To me it falls exactly within what the patch tries to achieve: report
> potential unintentional misuses of arrays.

That was indeed my exact intention when doing that patch.

>> Having multi-dimensonal arrays is
(Continue reading)

Yasuo Ohgaki | 3 Nov 2011 01:32
Favicon
Gravatar

[PHP-DEV] Zend Multibyte support

Hi all,

I noticed that "Zend Multibyte Support" won't be on with

./sapi/cli/php -d zend.multibyte=1
nor
zend.multibyte=on (in php.ini)

This happens both php-src and php-src-5.4.

According to php.ini-production from php-src:
; If enabled, scripts may be written in encodings that are incompatible with
; the scanner.  CP936, Big5, CP949 and Shift_JIS are the examples of such
; encodings.  To use this feature, mbstring extension must be enabled.
; Default: Off
;zend.multibyte = Off

I thought it became runtime option.
Is this a bug or am I missing something?

--
Yasuo Ohgaki
yohgaki <at> ohgaki.net

--

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Ferenc Kovacs | 3 Nov 2011 01:46
Picon
Gravatar

Re: [PHP-DEV] CI for 5.4

On Wed, Sep 7, 2011 at 11:29 AM, Hannes Magnusson <
hannes.magnusson <at> gmail.com> wrote:

> On Wed, Sep 7, 2011 at 03:53, Ferenc Kovacs <tyra3l <at> gmail.com> wrote:
> > On Wed, Sep 7, 2011 at 3:29 AM, Stas Malyshev <smalyshev <at> sugarcrm.com>
> wrote:
> >> Hi!
> >>
> >> Since we started to pay real attention to our unit tests now, I wonder
> if we
> >> could set up some kind of frequently-running CI system that could be
> used to
> >> screen commits and identify breakage early? That'd help with 5.4
> process I
> >> think.
> >> We have http://gcov.php.net/ but it doesn't run with the frequency I'd
> like
> >> and since it says the run takes 44 hours it's kind of understandable.
> So I
> >> wonder if we could have something that just builds it and runs unit
> tests
> >> and we could see it in the same format as on gcov? Ideally after each
> commit
> >> would be nice, but say once an hour or two (even fullest unit tests run
> >> should take more than that, I think) would be OK too. If we could have
> two
> >> of them, like Linux & Windows, it'd be even better, but at least one
> would
> >> be nice.
> >> What do you think?
(Continue reading)

Xinchen Hui | 3 Nov 2011 02:00
Picon
Gravatar

Re: [PHP-DEV] Re: [PATCH] Notice on array to string convertion

hi,
  we should only warn the un-intenional convertion .

   So , give third to send make printable zavl.  Sppress all the
intentional ones.

Thanks

Sent from my iPhone

在 2011-11-3,4:23,Patrick ALLAERT <patrickallaert <at> php.net> 写道:

> 2011/11/2 Etienne Kneuss <colder <at> php.net>:
>> Hi,
>>
>> On Wed, Nov 2, 2011 at 17:27, Stas Malyshev <smalyshev <at> sugarcrm.com> wrote:
>>> Hi!
>>>
>>>> What about array_diff(array("Array"), array(array()))? To me the sole
>>>> act of having an array in it is an almost sure indication that the code
>>>> is wrong somewhere... IMO it deserves a notice.
>>>
>>> That one would have the arrays different.
>>
>> Well, they are not different elements w.r.t array_diff, so it does
>> return array() since (string)"Array" === (string)array().
>>
>> My point is: there is an implicit usage of string representations  in
>> those functions due to the cast. And it can yield various unexpected
>> results.
(Continue reading)


Gmane