CodeIgniter Forums
Strange error in custom library - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Strange error in custom library (/showthread.php?tid=36318)



Strange error in custom library - El Forum - 11-28-2010

[eluser]Razican[/eluser]
Hello, I have modified the OnlineUsers library, and changed the file variable to one in the app/data/ directory. I have that section like this:

Code:
class Online_users{
    var $file    = APPATH.'data/online_users.tmp';
    var $data;

It says that there is an error in
Code:
APPATH.'data/online_users.tmp';

Code:
Parse error: syntax error, unexpected '.', expecting ',' or ';' in application/libraries/Online_users.php on line 15

How can I solve that?


Strange error in custom library - El Forum - 11-28-2010

[eluser]WanWizard[/eluser]
It's complaining about the concatenation dot, you can't put an expression in a class property declaration.


Strange error in custom library - El Forum - 11-28-2010

[eluser]Razican[/eluser]
I have changed that into this:
Code:
var $file            = 'data/online_users.tmp';
    var $data;
    var $ip;

    function Online_users()
    {
        $this->file        = APPATH.$this->file;

But it tells me this:
Code:
Use of undefined constant APPATH - assumed 'APPATH'

How can I use that constant into my library?


Strange error in custom library - El Forum - 11-28-2010

[eluser]Jeroen Brussich[/eluser]
don't you mean APPPATH ?


Strange error in custom library - El Forum - 11-28-2010

[eluser]Razican[/eluser]
Yes, that was the problem, but I get another error.

Is it possible to know the online users with the session class? doing this?

Code:
function online()
    {
        $query                = $this->db->get('sessions');

        return $query->num_rows();
    }

I mean, does the session class delete sessions from the database after $config['sess_time_to_update'] has gone? or it deletes them after $config['sess_expiration']?

It would be easier for me that way. I only want to know how many people has the last activity later than time()-$config['sess_time_to_update'].