Search code examples
namespacesdoctrinedoctrine-ormdqlbackslash

Escaping backslash in namespaces with DQL (Doctrine 2)


I'm a bit confused about writing queries in DQL. From the official documentation:

$query = $em->createQuery('SELECT u FROM MyProject\Model\User u WHERE u.age > 20');

Why the backslash of the namespace is not escaped?
I'm getting a warning in Zend Studio for that reason, and it works anyway, but I think is just "luck", because neither \M nor \U are valid escaped sequences.

What do you think? is safe to use that syntax? or is better to escape the "\" always in DQL?

$query = $em->createQuery('SELECT u FROM MyProject\\Model\\User u WHERE u.age > 20');

Solution

  • See Dynamic namespace names (quoted identifiers) should escape backslash

    Looks like the first syntax is just lucky. :) I haven't tried it myself, so if you say that query with escaping works just as query without escping, it's better use escaped queries.