Strict Typing And XML-RPC

You may or may not be aware web services are very strictly typed (well, XML is, period). That means if you send a web service a string, e.g. '233', when it wants an integer, e.g. 233 (note the very subtle difference) it will break!

Note it is now sending our node ID explicitly typed as a string. We will only get an error from this. =(

"Oh, that's ok" you say, "I won't be that dumb!" ... but what if that XML-RPC call is in a function? What if you're not the only one calling it? What if someone else *is* that dumb?

Their problem? Possibly. But yours when they tell you your function is broken and you spend three hours working out it isn't. Easy fix is to get in to the habit of explicitly typing any variables destined for a web service in PHP, something like this:

With the above code, even though some dufus has sent the node ID over as a string it doesn't matter. Because right when I send it off to Drupal's core XML-RPC functions I explicitly say "this is an integer, mmmkaay?"

We’re Code Enigma

We’re one of the most experienced Drupal teams in Europe, best known for our work on large, technically challenging projects for all kinds of clients.

Our team is passionate about Drupal and open source software. Our whole company spends at least four weeks per year working on Drupal modules or other open source projects. We’re also strongly committed to putting design first, taking a mobile-first, content-out approach to creating websites. This ensures that the sites we build combine the power of Drupal with best practice design and development.