SwiftlyTilting: usability, reusability

Thursday, February 10, 2011

An unexpected PHP quirk

The other day when I was doing work for a new client, I ran into a very strange error. I was configuring their Mediawiki site, but whenever I added code to the configuration file, it would cause a fatal error. Unfortunately the site’s error logs were not available to me. Initially I was baffled, though with some trial and error I was able to discover the problem. It was very minor and would have been discovered instantly if I had access to the error log, but it revealed an interesting quirk of the PHP engine, specifically: PHP does not require a closing semicolon at the end of the last line of the PHP script.

I was trying to add new configuration lines, and was baffled why any valid code except comments would cause an error. I eventually discovered that lines added at the top of the file worked correctly, and worked my way down the file to find which line was causing the error. Once I knew which line was causing the problem, the error was quite obvious, but until then, I had been baffled!

In a proper development environment where you have access to error logs, this will never be an issue, but when working “blind”, this is an unusual quirk that can cause some very unexpected and confusing results.

Thursday, October 14, 2010

Don’t close your PHP tags!

I saw this post over at sitepoint about whether or not you should close your PHP tags. Apparently there is some debate, though to me it seems pretty clear the choice is to leave them out.

If you’re unaware, the closing ?> tag in PHP files is completely optional. It is only really required if you are mixing HTML and PHP code, which itself is not a particularly good practice. Leaving off the closing tag prevents any erroneous white space or random characters from being sent to the output. It reduces the amount of code and prevents a possible error from occurring.

I can’t really think of a good reason to leave them on (assuming your document is pure PHP). Perhaps if you are from an XML background you will feel compelled to close the tag, but it’s entirely unnecessary in PHP.

Multiple frameworks and libraries such as Zend, CodeIgniter, Drupal and others suggest you to leave off the closing PHP tag as part of their style guide or best practices documentation, and I suggest the same. This is especially important for WinBinder developers (or anyone who uses php-win.exe), where any output sent to the console immediately ends the script.

Some have suggested dropping the need for <?php from php files completely. It’s not a bad suggestion, though i sort of think of it as analogous to #!/bin/sh in unix scripts. Those tags don’t need closing tags either.

So go out there and remove all those nasty ?> tags from your code ;)

WinBinder 2010.10.14 released - WinBinder is a PHP extension for making Windows Applications

I’m now “officially” maintaining WinBinder, so from now on you can get the latest version of WinBinder directly from Winbinder.org’s download page

Read my tutorial on getting started with WinBinder.
Visit the Winbinder Forums if you need more assistance

Changes since 2010.10.01

Added in 2010.10.14
* Fixed bug with return values for wb_sys_dlg_open when using wbc_multiselect
* Made 3rd and 4th parameters of wb_send_message optional

Added in 2010.10.13
* Additional flag parameter for wb_sys_dlg_open that accepts the option WBC_MULTISELECT. If this is enabled, all selected files will be returned as an array.

Sunday, October 3, 2010

Winter 2.2.1 Released - Winter is an Interpreted language for MediaWiki

Here is an update for Winter, the Wiki Interpreter.

Changes include
* added ^o and ^c escape characters
* added + to allowed characters in function names and functions
* added #reset_all_vars function
* added ++ and — functions
* fixed bug with #strpos and #substr returning false when it shouldn’t
* added #is_numeric, #is_int and #is_string functions
* fixed bug with array assignment
* other minor bug fixes

Winter Homepage on Mediawiki.org
Winter Documentation

Download Winter 2.2.1
Downloaded 1165 times

Saturday, October 2, 2010

New version of Winbinder, the PHP extension for making Windows Apps, released

New version of WinBinder… with some actual NEW FEATURES

Download WinBinder 2010.10.01
Downloaded 726 times
Tutorial on getting started
Winbinder Forum

This is a list of all changes since 0.46.190.

  • PHP 5.3 compatible
  • Unicode support added
  • Removed version checking from wb_windows.inc.php
  • Fixed memory leak in winapi library calls
  • Fixed bug where maximize wasn’t triggering WBC_RESIZE
  • Fixed bug where closing child windows would kill main window
  • Added WBC_NOHEADER style for ListView to disable the listview column header
  • Added WBC_MULTISELECT style for ListBox to that you can select more than one item
  • Added WBC_DEFAULT style to PushButton to make them display as the default button
  • ListView will respond to right clicks and fire WBC_RBUTTON
  • Window callback will pass WBC_GETFOCUS as an event when the window is focused
  • Window callback will respond to WM_HOTKEY(windows message) (experimental)
    New functions for use with the low level Windows API. These functions return pointers to callback functions, which are needed by certain WinAPI functions. The callback functions will send windows messages to the main Winbinder callback function, which will then trigger your PHP based callback function(s).

    • wb_get_midi_callback returns a pointer to MidiOutProc (can also be used for MidiInProc, WaveInProc, WaveOutProc or any similar callback) for use with functions like midiOutOpen
    • wb_get_enum_callback returns pointer to EnumWindowProc
    • wb_get_hook_callback returns a pointer to HookProc for use with various hooks.[/list][/list]

Finally got the time to merge my changes with Winbinder 0.5.0.. thanks to Ermac and Alec for their contributions to that version.

C source is included in the ZIP

Thursday, July 1, 2010

MediawikiPlayer v0.2.3

This version fixes additional security issues for servers with register_globals enabled.

Local Wiki page: MediawikiPlayer
Mediawiki Extension Page: Extension:MediawikiPlayer
Original post: Embed JW FLV Media Player with Mediawiki using the MediawikiPlayer Extension

If you find MediawikiPlayer useful, please consider making a $5 donation.


Download MediawikiPlayer v0.2.3
Downloaded 830 times

Thursday, June 10, 2010

MaintenanceShell 0.3.1

This version fixes a minor bug which caused a warning error to be displayed. This bug was introduced in 0.3.0

MaintenanceShell homepage on MediaWiki.org

Download MaintenanceShell v0.3.1
Downloaded 831 times

Thursday, May 13, 2010

cStruct and WinAPI: Classes for accessing the Windows API with PHP and WinBinder

One of the biggest roadblocks to writing code which accesses the Windows API is the fact that so many functions require you to provide data formatted in specific format. This format is defined on MSDN as a C struct, which has no direct representation in PHP. The best you can hope for is to figure out the layout of the structure, and then set up some PACK/UNPACK calls to convert the data to and from something more useful in PHP.

Enter cStruct, a collection of objects that helps provide support for C-like structures. All common data types have been implemented. This will save lots of time as you don’t have to remember or figure out how many bytes each datatype takes up and how to convert it to and from binary data.

Download cStruct.0.2.2
Downloaded 657 times
(more…)

Thursday, December 17, 2009

phc-win 0.3.1 - a PHP EXE compiler

The bugs in bcompiler seem to have been worked out since phc-win 0.3.0. Unlike 0.3.0, this release has the standard PHP DLLs (for PHP 5.3.1) and separate Winbinder, win32std and bcompiler DLLs. I’m hoping to be able to get a smaller DLL with all of the required extensions going, but for now this is better than the buggy bcompiler version.

If you find php-win useful, please consider making a small donation.


View the phc-win documentation.

Download phc-win 0.3.1
Downloaded 2002 times

Note to XP users:
You may need to install the Microsoft Visual C++ 2008 Redistributable Package (x86) for EXEs to run correctly.

Note to Windows 2000, 9x Users
Due to a change in 5.3.x series of PHP, phc-win does not work on Windows 2000 or 9x machines. There are no plans to compile a 5.2.x series binary for phc-win. If you cannot upgrade your OS, I recommend using phc-win 0.2.1 which uses PHP 5.0.5.

Check the phc-win category for the latest version.

Monday, September 7, 2009

SwiftlyTilting Wiki (re)Launches!

The wiki at SwiftlyTilting.com has received a face lift. I’ve also added documentation for all of my MediaWiki extensions, and there is a new sandbox area for users to try out Winter and my other extensions as well.

wiki.SwiftlyTilting.com

Validate XHTML | Word Press