PHP - - By Bruno Skvorc

PHPBot – Can a PHP Bot Help You Look up Documentation Faster?

I came across PHPBot the other day (not to be confused with Botman or Fondbot) – a “chatbot” which helps you look up PHP manual entries and generates example code for them.

If you follow me on Twitter, you know I don’t believe in chatbots being chatbots – as someone who’s built some for both commercial purposes and personal ones, and as someone who was around in the age of IRC auto-responding scripts, I see chatbots as a little more than a marketing fad designed to impress today’s Snapchat generation. However, every now and then one will appear that’s actually useful. Could this be the one? Let’s take a look.

Bot welcoming image

Concept

The idea is that you use the text input on the page to enter a PHP related term (like “ksort”) and the application will reply with an explanation and some example code, like so:

PHPBot reply to ksort input

Different queries will produce different responses. So, if you ask it for echo:

PHPBot's reply to echo

Usefulness

While this sounds interesting in theory, in practice it’s a bit off.

Knowledgebase and Bugs

The knowledge the bot can provide is limited at best. For example, asking it for preg_split copies the first example from the manual entry, but fails to recognize the newline and messes things up:

Preg split PHPBot response

Magic methods don’t seem to be supported:

PHPBot's response to __toString

And some queries will just fail, purely because there’s no example in the manual that the bot can find:

PHPBot's response to exec

Autocompletion / Suggestion

For the queries it doesn’t recognize, or for those a user had just started typing, it would be nice to have some kind of autocomplete or autocorrect dropdown – or at the very least, when asking for the wrong thing, the bot should be able to infer what we meant and suggest that. For example, preg_split which is identical to explode only it uses regex to split a string is quite stupidly named, and the bot recognizing this when we ask for preg_explode would be a great feature addition.

preg_explode produces nothing useful in PHPBot

Copy / Paste Friendliness

The snippets the bot returns are just code-highlighted blocks of text, but they’re not very copy-paste friendly. The lines don’t wrap either, so you’re never sure what you’re copying, and the bot sometimes misformats an example and messes up new lines, making it even less paste-friendly:

Broken newlines in returned example

A standardized shape of returned data would benefit the project considerably. A PSR-2 formatted plain-text output comes to mind as something cross-platform friendly which could then be consumed by any custom-made client (see API below).

API

The app as-is provides no API access, so it can only be used in a separate tab / browser. In an era where we all have over 20 tabs open at any one given time while working, yet another one isn’t exactly too useful – it’d work much better as a browser extension, really, but even better if it had an API.

Being able to implement it with any third party tool, client, or IDE would actually be quite exciting, and would significantly augment tools like class templates and code snippets in IDEs like PhpStorm!

Source Code

Right now, PHPBot is closed source. I assume this is because it was quickly hacked up and is little more than a crawler which grabs the relevant example from a queried method, if it can find one. That’s understandable, but I would encourage the author to clean up the code and open source it as soon as possible so that we as a community can dig in and make it do things the author didn’t think of.

Conclusion

PHPBot, while less a bot and more an “interactive” search field for the PHP manual with examples, has a limited scope of use. Right now, its knowledgebase is minute, and the examples within are less than useful. It’s a cute experiment, but little more than that.

At this point in time, I’d sooner recommend a thing like DevDocs which contains the full manual and works offline, thus being extra fast. PHPBot does show potential as an interesting tool / experiment, but won’t realize that potential until it opens up its source code and allows people to contribute example code to generate, and APIs to implement its responses in traditional chatbots that can be integrated with CLI tools, IDEs, and maybe even IM application clients – then, having an interactive, responsive, user-upgradeable manual that can be fully integrated with one’s local tool will become a game-changer.

It should be noted that the app is in beta right now, and that the author intends to take it much further. I had spoken to him on Twitter, where he’s very open to feature requests and feedback, so go give him some!

Did you check it out? What did you think?

Sponsors