• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
question about method chaining

#1
[eluser]杨帅[/eluser]
i got a "syntax error, unexpected T_OBJECT_OPERATOR" error, and i searched the forum, now i know it's because the php4 not allow method chaining. i shouldn't use the syntax such as
Code:
$this->db->orderby()
in my php4 web server.
instead of the upper one ,i should use
Code:
$db=$this->db;
$db->orderby();
but i searched the source of codeigniter , i found lots of statement such as:
Code:
if ($this->CI->db->cachedir == '')
        return $this->CI->db->cache_off();
    $path = $this->CI->db->cachedir;
    if ($this->CI->db->db_debug)
        return $this->CI->db->display_error('db_invalid_cache_path');
is this method chaining? i donno whecher it can run property in php4 server. anybody know this? great thanks.

#2
[eluser]coolfactor[/eluser]
Code:
$this->db->orderby()
That code works fine under PHP4. Were you missing a semi-colon at the end?

Method chaining (PHP5 only) is a very convenient shortcut which lets you access multiple methods on the same object in a single line of code:

Code:
$this->db->where('something')->orderby('something')->limit(5);

where(), orderby(), and limit() are all methods of $this->db (an instance of the Database class).

The CodeIgniter code you posted is not method chaining. It's just accessing a single property or method on objects attached to other objects.

#3
[eluser]杨帅[/eluser]
thank you coolfactor, you are really cool!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.