# Chaining of funtion calls

**URL:** <https://forum.kirupa.com/t/chaining-of-funtion-calls/302506>\
**Category:** Uncategorized\
**Created:** [January 1, 2010, 11:33pm UTC](https://forum.kirupa.com/t/chaining-of-funtion-calls/302506 "2010-01-01T23:33:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![NeoDreamer](https://avatars.discourse-cdn.com/v4/letter/n/ccd318/32.png) [@NeoDreamer](https://forum.kirupa.com/u/NeoDreamer)\
**Post date:** [January 1, 2010, 11:33pm UTC](https://forum.kirupa.com/t/chaining-of-funtion-calls/302506/1 "2010-01-01T23:33:41Z")

</div>

How do you do method chaining in PHP? See how many lines of code I need to write for this?

```php

    public function inboxTotal($userId)
    {
        $q = $this->db->query(
            'SELECT COUNT(*) AS count
            FROM message
            WHERE recipientId = ?',
            array($userId)
        );
        
        $result = $q->result();
        $row = $result[0];
        
        return $row->count;
        
    }

```

I’d rather do the following, but I always get an error saying _whatever_ is not a property _whatever_.

```php

    public function inboxTotal($userId)
    {
       return $this->db->query(
            'SELECT COUNT(*) AS count
            FROM message
            WHERE recipientId = ?',
            array($userId)
        )->result()[0]->count;
   }

```

This kind of stuff can be easily done in JS. I wish PHP were just like this.
