Closed olaulau closed 4 years ago
I know it the result of a divide, but it's rounded so it will never be a decimal.
That's not the reason.
The code:
148 function paginate(
149 $pos=0,$size=10,$filter=NULL,array $options=NULL,$ttl=0,$bounce=TRUE) {
150 $total=$this->count($filter,$options,$ttl);
151 $count=ceil($total/$size);
The relevant function:
https://www.php.net/manual/en/function.ceil.php
value rounded up to the next highest integer. The return value of
ceil()
is still of type float as the value range of float is usually bigger than that of integer.
correct ! but it is the result of $total/$size, which is <= $total ($size is >= 1 I suppose) and $total is an int ... so $count will never be greater that integer maximum.
correct ! but it is the result of $total/$size, which is ...
irrelevant. ceil()
always returns a float.
Cast it yourself in your own code if it's a problem.
.. hang on - how are you using $count
with pos()
(aka current()
) - that function doesn't use numbers, nor does it return the index.
$ cat /tmp/x.php
<?php
$total = 10;
$size = 5;
$count = ceil($total/$size);
$arr = ['one', 'two', 'three'];
$dummy = next($arr);
echo "pos()=".current($arr)."\n";
$ php -f /tmp/x.php
pos()=two
correct ! but it is the result of $total/$size, which is ...
irrelevant.
ceil()
always returns a float.Cast it yourself in your own code if it's a problem.
Of course I can cast, I just though it would be more consistent if all were integers.
.. hang on - how are you using
$count
withpos()
(akacurrent()
) - that function doesn't use numbers, nor does it return the index.$ cat /tmp/x.php <?php $total = 10; $size = 5; $count = ceil($total/$size); $arr = ['one', 'two', 'three']; $dummy = next($arr); echo "pos()=".current($arr)."\n";
$ php -f /tmp/x.php pos()=two
I was thinking of indices returned by paginate().
as written in the doc , the paginate function returns some infos. all are of type int, whereas "count" is of type float. I know it the result of a divide, but it's rounded so it will never be a decimal. so I this it has to be an int, so that strict comparison with "pos" will work.