Call to undefined function ‘output_cache_disable’

This is a Zend Studio warning that has been bugging me lately.

The culprit is the file dummy.php, distributed with Zend Debugger. As per the installation instructions provided by the README file, one should “4. Copy the dummy.php file to your document root directory.” but the project I’m currently reviewing (FengOffice 1.7.3.1) has three copies of that file in three different folders. So a build in Zend Studio always gives that warning three times.

I know that in this particular case, I could simply erase all the dummy.php copies in the project, and forget the issue. And that’s exactly what I’m going to do.

But the issue is caused by a common programming idiom in PHP.

{[ .dummy | 1.hilite(=php,ln-1=) ]}

The code calls a contextual function only if it exists (@3-5). This is certainly correct, but fools up the simple Zend Studio validator.

It would be better if the code defined the expected contextual function if it didn’t exist, and called the function in any case (@3-6).

{[ .smarter_dummy | 1.hilite(=php,ln-1=) ]}

This makes Zend Studio give no more warnings.

Anyway, all in all, I think that Zend Studio could be a little smarter and don’t give warnings for function calls inside function_exists blocks.

I know that this could be quite difficult to implement, so an alternative workaround could be an option for telling Zend Studio not to show a specific warning, specific up to the file and line, i.e. up to a single issue in the problems panel.

Delving into the code of FengOffice

FengOffice is an open source application for office automation. It’s a good piece of open source software.

For me, it’s best features are nested workspaces and nested tasks.

Nested workspaces help you segment your office into meaningful blocks, with any meaning you see fit. For example I have a Projects workspace and each project of mine gets its own workspace inside Projects. Into a workspace you can add any number of many different items: documents, notes, files, contacts, companies, events, milestones, tasks. Each workspace summarizes all the contained workspaces at any level.

Very surprisingly, I can make task hierarchies (also by means of the intuitive drag and drop interface) but I cannot sort sibling tasks, and FengOffice people are not going to add this functionality by them own.

So I downloaded and installed the FengOffice Community package, and started to delve into the code to understand how to add that functionality by myself.

In the above picture you can appreciate what surprised me even more than the lack of the feature I want to add. The default ZendStudio detects almost 5,000 issues into the FengOffice code.

ZendStudio let me tune what issues I want notified, so I decide to exclude from the build all the ones related to code inside the library folder. The code there belongs to software from third parties.

Also, some JavaScript code makes ZendStudio crash again and again when building the project, so I decide to change some option of the JavaScript preferences pane, and see if it solves the issue. Luckily that is the case: After I turn on Enable JavaScript semantic validation, the building works fine and completes successfully.

Above you see the result of the new build. Hmm, not as good as I hoped. There are only 60 issues less than before excluding the library folder from the build path.

Assignment in condition is an issue I’d like to see notified, but I turn it off.

Above you see the result of the new build. Hmm, not as good as I hoped. There are only 120 issues less than before turning off Assignment in condition.

Undefined local variable is an issue I really don’t care about, so I turn it off.

Above you see the result of the new build. Wow, that’s something! That single option accounted for more than 4,000 issues.

Really, undefined variable is a non-issue in PHP, so I’m glad to see that the number of issues is drastically reduced turning it off.

Nonetheless, there are still 645 issues. That is a huge number. Do I’m the only one watching the code through ZendStudio lenses?

Errors

There are 2 errors in FengOffice, and both are issues of the same kind: the implementation of an abstract class is incomplete. I think that that code is not used, but it’s a bit difficult to say with certainty. So, if it’s not used, why is it included in a FengOffice version?

Warnings

There are 643 significant warnings in FengOffice.

84 warnings are due to a Bad escape sequence issue. If I check the code, I see that ZendStudio is right. All those issues belong to regular expressions that are erroneously double quoted, without double backslashing included escape sequences. This is easy to fix, by converting double to single quotes. How did they get unnoticed until now?

There are many more warnings that I could see if I turned off one issue type after another. I can and will fix all these issues by myself, before delving further into the code. But I’m not going to do it as a lone developer, so I’ll now try to apply for a developer membership of the FengOffice Community package, and see if I get one.

Matrix I/O in PHP 5.3

Inspired by the Grid Computing challenge at Code Golf, I came up with a couple of useful functions for reading and writing matrices in PHP 5.3

{[.matrix | 1.hilite(=php=)]}

Here is a demo page

{[.demo | 1.hilite(=php=)]}

whose result is

 

$input = ' A, B, C, D, E FFF, G, H, I, J K, L, MM, N, P Q, R, S, T, UUUU VVVVV, W, X, Y, Z ';
$output = ' A, B, C, D, E FFF, G, H, I, J K, L, MM, N, P Q, R, S, T, UUUU VVVVV, W, X, Y, Z ';
$output === $input

After uncommenting the transposition line, the result is

 

$input = ' A, B, C, D, E FFF, G, H, I, J K, L, MM, N, P Q, R, S, T, UUUU VVVVV, W, X, Y, Z ';
$output = ' A, FFF, K, Q, VVVVV B, G, L, R, W C, H, MM, S, X D, I, N, T, Y E, J, P, UUUU, Z ';
$output !== $input