NAJAX is a PHP Ajax framework. Not only does it look easy to use, it also appears to have well-written and well-documented code.
One of the examples is a PHP Exam. I managed to score only 7 out of 12. A list of my errors in in the extended section of this article.
Posted by karma at 07:45 PM. Filed under: PHP Tips
• Permalink
After discovering about the debug_backtrace function (PHP >= 4.3.0); I was thinking about how wonderful it would be to attach a customized error handler to Nucleus when running in debug mode. This handler could output a stacktrace, which would be much more helpful than a message a la "Tried to call a method on a non-object at code.php line x" when this line of code is buried deep into the code.
Unfortunately -- as I discovered the hard way -- the error handler function that is passed to set_error_handler is never called for fatal errors. This behavior is listed in the manual, but I only bothered to read it carefully once things didn't quite work as expected. The reason why these fatal errors cannot be trapped is that the engine might not be in a stable state. Bummer. An extra class of errors (fatal unless trapped) would certainly be welcome.
Posted by karma at 06:41 PM. Filed under: PHP Tips
• Permalink
In this article, I'm re-creating the example from the Friendly Forms post using HTML_QuickForm (a PEAR package) and the Smarty template engine. I'm also looking into how to easily distribute PEAR with your application.
Posted by karma at 05:18 PM. Filed under: PHP Tips
• Permalink
Remember the What's wrong with this code? post from a week ago?
Niels catched most of the problems that I injected in the code. Allow me to describe the problems a little more detailed:
Posted by karma at 08:41 PM. Filed under: PHP Tips
• Permalink
Here's a challenge: I have a piece of PHP code, and it's up to you to find the possible issues with it. Security issues, code issues as well as issues with different PHP configurations and versions. Look at the code from the Nucleus perspective: a PHP script which will be installed on many different systems (for Nucleus: PHP versions 4.0.6 and up), and should run out of the box.
Solutions can be found in a follow-up post.
Posted by karma at 10:03 PM. Filed under: PHP Tips
• Permalink
I stumbled across a free e-book on PHP today: A Programmer's Introduction to PHP 4.0 from Apress.
Note that at the time of writing, the current PHP version was 4.0.3, so it might be slightly outdated.
Posted by karma at 06:24 PM. Filed under: PHP Tips
• Permalink
When using the echo "function" to output a string which is combined of multiple parts, once could write:
echo 'foo' . htmlspecialvars($someVar) . 'bar'
The problem with this is that PHP will first concatenate the three strings (two concatenations) before using echo to dump it to the output. This means that two extra string objects will be created into memory.
The alternative is using comma's. It looks a little weird, but echo then behaves as a function that is taking multiple parameters and dumping all of them:
echo 'foo' , htmlspecialvars($someVar) , 'bar'
In this case, no concatenation is needed which means this code should be faster and more memory-efficient than the concatenating version.
I know the effect of this will be very limited, but I try to use this wherever I can.
Posted by karma at 12:00 PM. Filed under: PHP Tips
• Permalink
In order to understand some parts of the Nucleus core code, you need to know what references are, how they work, and how to use them. This article tries to explain the basics of references. If you're familiar with programming languages like C or C++, this will look trivial. But remember: PHP references are NOT the same as pointers in C, they're more like symbol table aliasses.
Knowing how references work will help you understand the Nucleus MANAGER class and the Nucleus Plugin API.
Posted by karma at 08:12 PM. Filed under: PHP Tips
• Permalink
On the PHP website, there's a list of backwards incompatible changes made in PHP5. There's not much to worry about: apart from the fixes already applied to Nucleus, there are no new issues.
Posted by karma at 09:17 AM. Filed under: PHP Tips
• Permalink
In order to make sure Nucleus runs on as much servers as possible, my PHP setup (php.ini) is set up in a way to make the environment as hard as possible to work with. TeRanEX requested an overview, so here it is:
Posted by karma at 02:44 PM. Filed under: PHP Tips
• Permalink