Using Heredoc Syntax for Improved Syntax Highlighting

If you find yourself writing PHP code containing other languages (JS snippets, SQL queries, etc.), you can use PHP’s Heredoc syntax for improved syntax highlighting, at least in VS Code.

Basically, Heredoc syntax uses <<< to note the beginning of a string, followed by an identifier. Everything until the next instance of that identifier is treated as a string.

Here are examples:

You may not get autocompletion and other IDE features, but at least it’s easier to read.

What you choose for the identifier does impact the syntax highlighting…for example, if I had used SQL instead of JS in the example above, the code would have been highlighted differently. I suspect this is a feature of ProseMirror, though I haven’t dug into it to find out for sure.

Trello to Excel

I was trying to export a Trello board to a spreadsheet and include all the cards and checklists but couldn’t find a good way to do that, so I wrote one!

Originally this project was based on Laravel Zero, a command-line Laravel framework. It accepted a JSON file exported from Trello and exports an Excel spreadsheet:

  • A board becomes an Excel file
  • Each list becomes a worksheet
  • Each card becomes a row in the worksheet
  • Checklist items become individual rows with their name, completion status, and due date

It still does that, but it’s also available now as a webapp for anybody to use simply by logging in with Trello!

Try it out here: https://trello-to-excel.andrewrminion.com/

You can find the source code here: https://gitlab.com/andrewminion/trello-to-excel

Example

Using psysh in Shared Hosting or Limited User Environments

When using psysh or Laravel’s php artisan tinker in a limited user’s environment, you may run into this error:

Unable to create PsySH runtime directory. Make sure PHP is able to write to {some directory path} in order to continue.

This is caused by psysh trying to use a path that’s not accessible to the user.

To fix, add a file at ~/.config/psysh/config.php with this content:

<?php
return [
    'runtimeDir' => '~/tmp'
];

Visual Studio Code Workspaces and PHP Intelephense

When developing WordPress plugins for general use, I like to open the plugin directory itself in VS Code.

This allows me to use the git integration and terminal without wading through the wp-content/plugins/{plugin name} directory structure.

However, this results in the WordPress functions appearing as “undefined function” and the inability to jump to their definition or hover to see parameters and other details.

Here’s how I fix that annoyance:

  1. Save the open project as a workspace (File > Save As Workspace…)
  2. Add a fresh WordPress installation to the workspace, making it a multi-root workspace
    • Note: this step is not strictly necessary as noted below.
  3. Go to Settings (Code > Preferences > Settings), click on the “Workspace” tab, and search for intelephense.environment.includePaths
  4. In the “Include Paths” section, add an entry for the fresh WordPress installation so Intelephense will index it

Unserialize.dev

php iconA quick-and-dirty PHP script to unserialize a string in PHP.

Clone (or download and expand the zip file) into your documents root and point unserialize.dev to the folder.

Note: as of December 2017, Google Chrome requires a TLS certificate to access .dev domains. You can use the script on any local TLD or PHP-capable server without any changes.

Enter your serialized data into the textarea, hit “submit,” and boom!—your serialized data is expanded to a much more human-readable view! Now includes Kint debugger to make it even easier to explore your data. Continue reading “Unserialize.dev”

Object-Oriented Programming: a helpful series of articles

Not having formal training in computer science or programming, I’ve struggled to understand object-oriented programming. This course by Tom Mcfarlin was extremely helpful in explaining the basic concepts, particularly in regards to WordPress development.

Download an ePub: OOP in WordPress

Update: since Readability was shut down, here’s a link to the original course content.

 

Posted in PHP