ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Stats module give PHP error

April 07, 2011 11:49am

Subscribe [5]
  • #1 / Apr 07, 2011 11:49am

    o_cee

    16 posts

    Using 2.1.4 beta.

    The following code generates an error:

    {exp:stats channel=“artikel”}{last_entry_date format="{DATE_W3C}”}{/exp:stats}

    A PHP Error was encountered
    Severity: Warning
    Message:  Invalid argument supplied for foreach()
    Filename: stats/mod.stats.php
    Line Number: 177

    Quickly looked at the code and it seems to be related to member counting, not the tag I’m interested (which is printed okay despite the error).

  • #2 / Apr 08, 2011 5:41am

    John Henry Donovan

    12339 posts

    o_cee,

    Was the beta a fresh install or an upgrade from EE2.1.3?
    Do you have a Freelancer license?

    IS that tag nested within another tag?
    Can you test it on a completely blank template please?
    Is your member module installed?

  • #3 / Apr 08, 2011 5:50am

    o_cee

    16 posts

    Pretty sure it was a clean install of 2.1.4 beta.

    It is the commercial license.

    The tag is not nested, complete code is here:

    <?xml version="1.0" encoding="UTF-8"?>
    <urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 <a href="http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"</a> >
        <url>
            <loc>{homepage}</loc>
            <lastmod>{exp:stats channel="artikel"}{last_entry_date format="{DATE_W3C}"}{/exp:stats}</lastmod>
            <changefreq>hourly</changefreq>
            1.0</priority>
        </url>
    </urlset>

    Same error with just

    {exp:stats channel="artikel"}{last_entry_date format="{DATE_W3C}"}{/exp:stats}

    in empty template.

    Member module is not enabled, but installing it (enabling it) does not make any difference.

  • #4 / Apr 08, 2011 6:55pm

    Sue Crocker

    26054 posts

    Hi, o_cee. I just tried this with EE 2.1.4 beta on my test-ee site:

    http://test-ee.com/index.php/sample/query

    I just changed the channel to news, since I’m using the Agile theme.

  • #5 / Apr 08, 2011 7:45pm

    o_cee

    16 posts

    Hi Sue

    I’m not sure how that’s supposed to help me..

    /Oscar

  • #6 / Apr 10, 2011 1:20pm

    Greg Salt

    3988 posts

    Hi Oscar,

    I’m afraid that I can’t replicate this error either. Is this being used on a live site with a membership system? Are you using any addons? If so, please let us know what they are.

    Cheers

    Greg

  • #7 / Apr 10, 2011 2:56pm

    o_cee

    16 posts

    Hmm..

    No membership system. Site not live yet.

    Addons: Playa, Channel Images, Channel Videos, Taggable.

    I’ll see if I can debug it myself, got any suggestions for what to look for?  Have quite a bit of experience with PHP, but not CI.

  • #8 / Apr 10, 2011 3:35pm

    o_cee

    16 posts

    Okay, got the reason for it debugged now..

    As my error message says, it is line 177 in modules/stats/mod.stats.php. This code block is in a conditional that checks for:

    if (count($this->EE->stats->statdata('current_names')) > 0)

    The problem is the use of count() and how EE_Stats::statdata returns an empty response:

    libraries/Stats.php

    /**
     * Get Statdata
     *
     * This method will retrieve items or the entire statdata class property.
     *
     * @param       string          which piece of the array to get (optional)
     * @return      mixed           FALSE on failure, string or array on success
     */

    Note that it returns FALSE on failure, which we will get in this case since we don’t have the member module(?). However, count(FALSE) will return TRUE:
    http://php.net/manual/en/function.count.php

    Which is why the code at line 177 in modules/stats/mod.stats.php is executed at all, when it shouldn’t, thus giving FALSE to the foreach causing the original error I posted.

  • #9 / Apr 11, 2011 4:54pm

    Sue Crocker

    26054 posts

    Hi, o_cee. I turned of the membership module, and still don’t get an error when I post the code you used all by itself in a stand alone template.

    I’m using a fairly clean 2.1.4beta install on MediaTemple. Also tested on a local install with 2.1.4 beta. Still no errors. Let me ask my other TSS helpers if they get the same error.

  • #10 / Apr 11, 2011 6:06pm

    o_cee

    16 posts

    Sue,

    What is your “Enable Online User Tracking?” set to?

  • #11 / Apr 12, 2011 6:11pm

    Sue Crocker

    26054 posts

    It’s set to on.

  • #12 / Apr 12, 2011 7:01pm

    o_cee

    16 posts

    Try turning it off, see if that gives you the error.

  • #13 / Apr 12, 2011 8:58pm

    Brandon Jones

    5500 posts

    Hi o_cee,

    Yep, I can replicate this and we’ll get a fix into the next release. For now you can change line 147 (not 177) of system/expressionengine/modules/stats/mod.stats.php to

    if ($this->EE->stats->statdata('current_names') AND count($this->EE->stats->statdata('current_names') > 0))

    Thanks!

  • #14 / Apr 13, 2011 7:01am

    o_cee

    16 posts

    And making sure this is redirected back to the original ticket I created: https://support.ellislab.com/bugs/detail/15599/

  • #15 / Apr 13, 2011 11:17am

    Brandon Jones

    5500 posts

    Thanks for pointing that out, Oscar! We got it marked as fixed for the next release. I’ll go ahead and close this but please don’t hesitate to post again.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases