beyond tellerrand / btconf 2014

It was the month of may – it was btconf time! Lucky me: I was able to attend this years beyond tellerrand conference in Dusseldorf again. It was for the fourth time Marc Thiele hosted this curated web conference and again, he managed to have really famous speakers on stage:

Weiterlesen

JavaScript Pitfalls for PHP-Developers

A couple of years ago, PHP developers only had to have strong knowledge in the language itself and experience in some PHP frameworks and libraries, additionally skills in MySQL were expected.
If we take a look at our current job advertisement, these knowledge is still important, but also skills in JavaScript are asked and strongly desired. If you wonder why JavaScript is so popular at these times, my answer is quite simple: The browser is no longer a stupid instrument to view some static websites on the internet- the browser turned into an (Web-) Application Platform that provides more content then plain text. This results in more and more complex sites and therefore in much more source code. One of the reasons for this progress is AJAX, which is the art of exchanging data with a server, and updating only parts of a website (with JavaScript). Therefore JavaScript is the big winner on this evaluation, because it is available on nearly every browser, needs no plug in or any additional software and it is easy to learn. In the early days of the internet we used JavaScript to create some lousy effects or did some simple checks for any input fields. These days are gone, it is not unusual to have more JavaScript code than PHP code in large projects. Coding with JavaScript is not the same as coding with PHP, that´s the reason why I will write down some typical pitfalls for a PHP developer whose coding JavaScript.

Data types

There are two major data types in JavaScript, the primitive one (Boolean, String, Number, …) and Object (Array, Function). To check the data type the keyword typeof keyword might help you. But be aware! Objects are the fundamental units of JavaScript and virtually everything in JavaScript is an object and takes advantage of that fact. Even the primitive data types have so called “primitive object wrapper” and there´s great potential for wrong usage of the typeof keyword and checking the data type. Here is a small overview what you will get if you use the typeof keyword with several variables:

Variable

typeof Variable

{company: ‚Mayflower‘}

object“

[‚Mayflower‘,’PHP‘]

object“

function(){}

function”

a simple String”

string”

123456789

number”

true

boolean”

new String(“Mayflower”)

object”

new Employe( )

object”

You can see, you will not always get what you expect. Therefore it´s not always a good choice to check the data type with typeof. A better approach is to use the constructor property to identify the data type of a variable.


var myArr = [ ];
if (myArr.constructor === Array) {console.log(“yes, I am an Array!”)}

The downside of this approach is the needed comparison to a known data type. If you create your Array with the new operator, you can get the data type with the prototype property, like this:


var myArr = new Array();
console.log(myArr.prototype); // Array()

Array !== Array

In the PHP world an array is a wildly used data type and we are differ between the zero indexed, comma separated array and hash tables of key-value pairs, better known as associative arrays. In JavaScript an Array is just a simple zero indexed list of values- nothing more. There is no associative array in JavaScript. There is no trailing comma support for IE (causes an error)


var myArr = ['Mayflower','PHP','JavaScript'];

In JavaScript is something like an associative array, but this has nothing to do with the Array data type. The JavaScript world calls this an object literal and is a collection of key value pairs.


var obLiteral = {company: “Mayflower”, offices: ['München','Würzburg'] };

By the way, you are right if you say “the syntax looks like for a JSON string”. The syntax for an object literal and a JSON string are pretty similar with one main difference: For a JSON string the property names need to be wrapped in quotes to be valid. For object literals the quotes are only required if the property name have spaces or any other not valid identifiers.

for (… in … ) !== foreach

When you are working with Arrays the you surely know the foreach construct to iterate over the array. Against the common opinion, the for (… in … ) construct is not the JavaScript equivalent of foreach and it is not the best way to iterate over an array in JavaScript.

DO: Use the for (…) loop for iterations over array objects
Every JavaScript array provides a length property, so it is the best practice for iterating over a JavaScript using a simple for construct.

DON´T: Use the for (… in …) loop for iterations over array objects
It is not impossible to use the for (…. in … ) loop with an array (you remember, arrays are objects, too), but it can lead to some ugly errors because JavaScript is a powerful language and you can add functionality and properties to nearly every existing object (this is called augmentation). If you iterate over an augmented array object you will not get only the elements of the array, you will even get the augmented functionality and this may occur in an error.

The thing with the semicolon

Have you ever heard about “line termination with semicolon insertion”? JavaScript provides a mechanism that adds a semicolon to the end of a line if you forget it. At a first look this may be helpful but it can be the reason for endless debugging sessions. Imagine the following situation:


function user(){

return


{

company: “Mayflower”,

business: “PHP Development”

}

}

The user function will run without any error and will return a valid value (Ok, it´s undefined but it´s a valid return value). It´s not the desired object literal because the semicolon insertion terminates the function after the return.

I´m sure there are a lots of more pitfalls for PHP Developers, if you are interested in real crazy JavaScript I recommend a visit at http://wtfjs.com/.

YAML – Yet Another Multicolumn Layout

What is YAML? YAML is a framework to develop flexible layouts based on (X)HTML and CSS. In my opinion the best features of YAML are that it is flexible and easy accessible and not to forget that it is compatible with many browsers. Furthermore, it gives you maximal freedom concerning design. You can work with ‚any order columns‘ and the stylesheet drafts are very functionally arranged. The separators and backgrounds of columns can be designed without including any graphics. The subtemplates are suited to build multifunctionally applicable, flexible and nested grid modules.

Which browsers are supported? On Windows Internet Explorer 5.0 up to 7.0 is supported, on Linux Konquerer 3.3+, Galeon 1.3+, Epiphany 1.4.8+ and Lynx. Macintosh OS Safari 1.0.3+ and Camino 0.6+. And across operating systems Firefox 1.0+, Mozilla Suite 1.7.1+, SeaMonkey 1.0+, Netscape 8.0+ and Opera 6+ . As you see, quite a lot!

What is meant by: accessibility and web standards? The XHTML code and the stylesheets are of course valid. Many browsers are supported, as you just have read before. YAML abandons layout tables because it arranges its columns arbitraryly to get best performance with screenreaders and search engines. As a result you achieve more flexibility as to the layout and print arrangement and the rendering gets faster.
As to accessibility YAML has a so-called skip-link-navigation which means that screenreaders can get the relevant contents faster.

What’s the principle method of practice? YAML is working with the top-down principle, from the general approach to special solutions. Therefore an across browser, fully functional, modular constructed basic layout is available. The web designer,however, has to modify it and optimize the XHTML and CSS code and needs to remove all elements from the layout which are not necessary.

What layouts can you build with YAML? You can design layouts with one to three columns both with fixed or flexible widths. Or you can just construct flexible grid modules with subtemplates. The column system can get nearly arbitrary expanded so there is the possibility to design grid modules. HOWEVER; YAML is NOT a ready layout which you can take and that’s it: You have to adapt it to your needs and optimize it, that is delete all unnecessary elements otherwise it affects the performance.
The architecture of the XHTML and the CSS structure of the basic modules guaruantees independence from the constitution of later integrated contents. The enclosure of the basic elements in separate div-containers protects the correct positioning of the elements no matter how the later usage of the containers will be.

How much does YAML cost? Well, YAML has been licensed under creative commons attribution 2.0 (CC-A 2.0) since version 2.2 and permits the free use of the framework for non-commercial and commercial use provided the name of the author and a backlink to the project homepage remains in the footer or the imprint. Alternatively, there are also 2 commercial-license models to buy YAML.

What version is YAML? YAML is permanently developed further. Since 2008-05-24 the version 3.0.5 has been available. If you separate your own source code from the basic YAML source code you can easily update to the current version.

Where do you get YAML? You can download YAML at Dirk Jesse´s homepage: http://www.yaml.de.

Migrationsconsulting PHP 4 zu PHP 5

München/Würzburg, 3. April 2007:

Das Systemhaus Mayflower aus München startet aus aktuellem Anlass ein
Consultingpaket zur Migration von PHP 4 Applikationen auf PHP 5.

Seit Juli 2004 steht Entwicklern PHP 5 mit seinen erweiterten
Funktionen, einer verbesserten Objektorientierung und der kompletten
Unterstützung von Webstandards wie XML und SOAP zur Verfügung.

Trotz dieses langen Zeitraumes laufen immer noch mehr als 80%
aller Webapplikationen unter PHP 4 und verschenken so die Vorteile, die
ein Wechsel auf PHP5 bringen würde (Quelle: PHP Versionsstatistik
Februar 2007 von nexen.net). Wie aus dem Team der Core Developer von
PHP verlautete, wird nun jedoch
der Support von PHP 4 zum Ende des Jahres voraussichtlich eingestellt.
Gerade mit dieser angekündigten Einstellung des Supports von PHP 4
muss nun aber die Migration bestehender Anwendungen erfolgen,
um deren Zukunftsfähigkeit zu sichern.

Weiterlesen

Methods to reduce the load of your webserver by caching content: using lighttpd, MySQL UDF, LUA and speed everything up.

The method I would like to describe is based on the webserver
lighttpd.

Lighttpd is a single process webserver written for high traffic sites.
It supports fast-cgi out of the box which makes it ideal for hosting PHP applications.
There are lots of nice modules for the daily
work like mod_access or mod_rewrite.
For more infos see the internals

There are also some benchmarks there.
Lighty´s home is always worth having a look at.

Weiterlesen