CSI: PHP

"Looking at your tweets I cannot even fathom what your job is. CSI:PHP?" — @grmpyprogrammer

If the Method Is Named getOne, Why the Foreach?

| Comments

I’ll leave this to you to rip apart.  My head hurts too bad from banging it against the desk to do any real analysis, and it’s not even my code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
class Db
{
    // snip

    function getOneWithDetail($id=0)
    {
        $q = $this->createQuery('t')
            ->orderBy('t.title ASC')
            ->where('t.id = ?', $id);
        $objCollection = $q->execute();
        foreach ($objCollection as $objTitle) {
            return $objTitle; //there should be only one 
        }
    }

    // snip
}

Thanks to Agustin Casiva for the submission.

Comments