phpnumericbbpress

Numeric value issues with high values, not with low values


The code (the issue occurs on the third line):

$post_count = bbp_get_topic_reply_count();
$post_count = $post_count++;
$page_count = round($post_count / 15 );

if (!empty($_POST['jump_page'])) {
    $jump_page  = $_POST['jump_page'];
    $topic_id   = bbp_get_topic_id();
    header('Location: https://url/?p=' . $topic_id . '&paged=' . $jump_page);
}
if ( $page_count > 4) {
//do something

When $page_count gives a low value there is no problem. Don't know exactly when, but when $page_count is supposed to give a high value I get the following Notice: A non well formed numeric value encountered in /.../...

I tried replacing 15with a string and round($post_count / 15) with:

Some help would be much appreciated.


Solution

  • For those stumbling onto this post, this was the solution:

    bbp_get_topic_reply_count() gives of a value with a comma. So I changed:

    $post_count = bbp_get_topic_reply_count();
    $post_count = $post_count++;
    $page_count = round($post_count / 15 );
    

    into

    $post_count = str_replace(',', '', bbp_get_topic_reply_count());
    $post_count++;
    $page_count = ceil($post_count / 15 );