Re: Updating legacy code ...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



http://php.net/manual/en/function.count.php

 Returns the number of elements in array_or_countable. When the parameter is neither an array nor an object with implemented Countable interface, 1 will be returned. There is one exception, if array_or_countable is NULL, 0 will be returned.

If the item is null, it should indeed return 0.

On Mon, Mar 4, 2019 at 9:59 AM Lester Caine <lester@xxxxxxxxxxx> wrote:
On 04/03/2019 14:23, Christoph M. Becker wrote:
> On 04.03.2019 at 14:58, Lester Caine wrote:
>
>> The one that is causing the most agro is complaints about using 'count'
>> especially when they are being thrown in the cached templates used by
>> Smarty and other elements of the framework. IS it now required that
>> there is a separate check of the item being counted exists where
>> previously it simply returned '0'? Throwing (array) in front of each
>> just seems totally wrong, but the whole framework runs on the principle
>> that an element is created when there is one or more values, and there
>> being zero of those elements is flagged by it's absence in the bigger
>> associative array. I've yet to work out just how Smarty is handling this
>> problem and hacking the cache to add (array) quietens down the
>> complaints ... but what is the correct way of handling this?

> If I want to know whether my purse is*empty*, I don't have to*count*
> the coins.  So, use `!empty($item)` instead of `count($item)`.

So we have to do extra checks ... and re-write all the existing code ...
echo count($item);
used to simply return '0' or the number of items and the templates use
that simple form where one displays the totals ...

--
Lester Caine - G8HFL
-----------------------------
Contact - https://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - https://lsces.co.uk
EnquirySolve - https://enquirysolve.com/
Model Engineers Digital Workshop - https://medw.co.uk
Rainbow Digital Media - https://rainbowdigitalmedia.co.uk

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux