We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Bound parameters syntax

I'm interested in finding out why the double-colon syntax was used for double parameters instead of the default PDO way of binding with a single colon in front?

In other words, why are bound parameters in Phalcon models done like so:

array('id = :id:', 'bind' => array('id' => $id));

while in adapters it is still done like so:

array('id => :id', array('id' => $id));

It seems like an annoyingly minute difference, and looks to me like it might cause more compatibility issues later on than it's worth. For example, migrating queries might be a pain if one has to un-standardize all bind params in their where clauses (if migrating from model x to Phalcon's model, for example).



98.9k

Yes, interesting point, maybe we could implement both syntax for named parameters making easy to migrate from other high level query languages or from PDO. thanks for the suggestion

That would be good, but I would go as far as making a breaking change and removing the double-colon syntax completely, or at least deprecating it in the docs and the API IDE plugins. Multiple choices such as this one should, in my opinion, be brought down to the minimum in order to minimize critical branching later on and to avoid the formation of two different schools of thought on the same thing. These issues do start small, but have the potential do get out of hand, and wasting time on maintaining a secure implementation of both double and single-colon syntax might not be in anyone's best interest.

Maybe we can use the new syntax and throw a warning exception that the other syntax will be deprecated in a near future version. Say keep it until 1.5 and then deprecate it.

I don't think throwing anything would be a very user friendly approach. In my case, I have all my notices and warnings in my apps configured to be fatal errors, so a sudden breaking of my application would not be a welcome change. I agree, however, that the old syntax should probably be kept until around 1.5 and people should gradually be introduced to its deprecation. Maybe add a "strict" mode into Phalcon, where if the user passes in "--strict" when building/installing/running Phalcon all deprecated methods throw warnings, and leave the regular mode as is, but remove the double-colon syntax from both in 1.5? That way everyone would be informed early enough to change their code, and they would even have a chance to test it by installing the "--strict" version locally.

edited Jun '14

I totally agree with @Bruno Why we have to use different syntax for binding params? (double colon for model and single colon for DAL). The difference makes more confusion, so I think we should have a standardization, choose only one syntax! :-)