Web Publishing, Programming, Algorithms, Languages, C, C#, PHP, SEO, CMS, Webserver, Miscellaneous, Gaming, Operating Systems, Security, Privacy

goto statement in PHP

Goto or not to go?

Goto is a very controversial programming statement. When discussing goto, some programmers talk about "spaghetti code" and think of BASIC, others answer with "performance" and think of C.

I'm one of the latter guys. My attitude to coding is, the coder should be able to decide what's the best way (in any means) to achieve the development goals.

Okay, there are only few good reasons to use the goto statement. Actually I can think of only one good reason: leaving a function at its end and place a generic cleanup there ("single point of exit").

Example:

PHP Error: Creating default object from empty value

PHP 5 introduces the E_STRICT error reporting constant. The PHP manual states "Enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code.". Thus it's recommendable to enable strict PHP errors.

About strict mode (E_STRICT)

Enabling the strict mode is done via the INI file (php.ini) or via code during runtime:

  ini_set('error_reporting', E_ALL | E_STRICT);

The above code sets error_reporting to E_ALL and E_STRICT, because E_STRICT is not part of the E_ALL constant.

Smarty templates and PHP iterators

Smarty templates are a very useful tool and I'm addicted to Smarty for a couple of years now. All projects I did use Smarty templates. Now it's 2009 and PHP 5.2 is stable and has a good performance. Therefore I decided to use any of PHP 5's features when they come along my way.

Recently, Iterators came to close and I had to implement one. It's usefull for proxying and also for dynamically presenting views of lists. Therefore my implementation looks like:

class Foo {
  var $childs;
 

SVN (Subversion): Move files to new folder

Today is the day of short articles. This one is really trivial. You'll agree as soon as you read it.

TortoiseSVN makes moving versioned files very easy. Moving files is the usual Windows procedure: hold down the right mouse button over the set of files to move. Then drag them to the new folder and select "SVN move versioned files here".

Well that's easy. But there is one pitfall that might make you ask: "Why the hell is no such menu item on my Windows box?"

The answer ist really really (believe me) REALLY simple. Subversion can move versioned files to versioned folders only! So:

Using commas in SEO friendly URLs

Just a quick note about comma seperation in a URL:

The standards state a comma (,) character is reserved for special use in URLs, whilst they don't tell what the special use might be. As well the practical use of comma in URLs is much less strict. Many CMS use comma seperated lists in URLs to pass information to the URL target.

Proxy pattern with PHP 5

PHP from version 5 on provides reasonable object support. Well the language is not really object-oriented, but hey, it's a scripting language!

Recently I had the chance to implement the proxy pattern (one of my favourite design patterns) in PHP. My goal was to make object relations more dynamical. Lets start from a simple assumption of two kinds of objects:

class Parent {
 var $ID;
 var $Child;
}
 
class Child {
 var $ID;
 var $Parent;
}

As you'll notice, both classes reference each other. Parent points at Child and Child points to Parent.

How to remove white space underline at end of links...

This is a very short and quick solution for web designers. The situation of today is an style link becomes trashed when having any kind of white spaces just before the closing

Imagine a link like:

<a title="example">
 example
</a>

will result in a display like:
example 

This is a bug of all browsers I know, but there is a quick PHP fix for it:

$html_source = preg_replace( "/\s+<\/a>/i", "</a>", $html_source );

Joomla! (Hawaiian for "Help me!") ;)

It's some weeks ago I had the pleasure to try diving into Joomla's component development. Today I must admit: I gave up and began to code my own CMS around the old project of mine that I intended to replace with a Joomla site. Finding out how to code for Joomla is no fun at all, as it is not for Drupal, too.

HTML TextArea with syntax highlighting (a brief overview)

This is just a short note I make to remember what I just found on the web. You perhaps no the WYSIWYG editors out there, converting an ordinary <TextArea> to a full featured text editor similar to Microsoft Word (or lets say OpenOffice Writer).

Basics: How to cache PHP websites

PHP might be the most often used Internet programming language. One reason might be it's so simple and docile even a beginner without much experience can use it.

When a website becomes older and mature, and starts to attract more people a day, many webmasters face a new competition: keep the scripts running, performing good enough to be usable to their visitors. This is the time where one has to think about performance-tuning PHP. One way to achieve better performance is, to plug in better hardware. Another way (the one we choose for this article) is to fine-tune the software side at PHP level.