-1

I am developing an application using Symfony2 and DQL for building some queries in the repositories. I have the next code in the controller:

$emGalPak = $this->getDoctrine()->getEntityManager();
  $OsatugabeKop = $emGalPak->getRepository('AnotatzaileaAnotatzaileaBundle:GalderaPaketea')
                             ->getOsatugabeKop(); 

and this is the query I built in the repository corresponding to the entity mentioned above:

<?php

namespace Anotatzailea\AnotatzaileaBundle\Repository;

use Doctrine\ORM\EntityRepository;

/**
 * GalderaPaketeaRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class GalderaPaketeaRepository extends EntityRepository
{
    public function getOsatugabeKop()
    {
        $qb = $this->createQueryBuilder('c')
                   ->select('c')
                   ->where('c.Osatua = 0')
        $Emaitza = $qb->getQuery()->getResult();

                return sizeof($Emaitza);

    }

}

When running the code it shows the next error:

Parse error: syntax error, unexpected T_VARIABLE in /var/www/Symfony/src/Anotatzailea/AnotatzaileaBundle/Repository/GalderaPaketeaRepository.php on line 20

Any idea on how I can solve this error?

j0k
  • 22,600
  • 28
  • 79
  • 90
Haritz
  • 1,702
  • 7
  • 31
  • 50

2 Answers2

2

This has nothing to do with your query not working.

When you see a "Parse error" that means your PHP code itself is improperly formatted and the PHP engine cannot even parse it, let alone run it.

In this particular case, you're missing a semicolon at the end of your expression creating the query builder.

public function getOsatugabeKop()
{
    $qb = $this->createQueryBuilder('c')
               ->select('c')
               ->where('c.Osatua = 0'); // <--- right there
    $Emaitza = $qb->getQuery()->getResult();

    return sizeof($Emaitza);
}

When you get the unexpected T_VARIABLE error that's almost always because you omitted a semicolon and the parser encountered a variable before it thought it should. It's easier to see the mistake if you take out the whitespace.

// Bad Code, two lines
$now = time()
$one = 1;

// Bad Code, one line
$now = time()$one = 1;
// ----------^  Pretty obvious now that a semicolon is missing
// And that a variable was encountered unexpectedly

Cheers

Peter Bailey
  • 105,256
  • 31
  • 182
  • 206
  • I'm always surprised by how people don't see this. The php error messages are so concise and clear as to what the problem is. – Flukey May 10 '12 at 18:50
0

Semicolon missing after where line.

Mun Mun Das
  • 14,992
  • 2
  • 44
  • 43