Archive for August, 2006

PHP Video: Processing Forms with PHP – part 2

Tuesday, August 29th, 2006


PHP Video Tutorial

Part two of my beginners video tutorials on how to use PHP to process HTML forms.

Video: PHP and forms video tutorial

Having covered the basics of forms in the first video, I now jump into the actual PHP code and introduce (for the first time) a built-in PHP construct called ‘Super Globals’.

We learn that Super Globals are associative arrays (that they hold lots of useful information,) that are automatically created by the PHP engine.

In this case we look at the three super globals that hold form data:

  • $_POST
  • $_GET
  • $_REQUEST

Stefan Mischook

PHP Interfaces: when and why you should use them instead of classes?

Saturday, August 26th, 2006

In this article/podcast, I look at what php interfaces are, and when and why we would use them over classes.

AUDIENCE:

To follow along, you must know the basics of object oriented php.

-

Download the MP3: PHP Interfaces Explained.

The following notes are meant to support the podcast … I left the details in the podcast.

First, what are interfaces?

  • Interfaces are 100% abstract classes – they have methods but the methods have no ‘guts’.
  • Interfaces cannot be instantiated – they are a construct in OOP that allows you to inject ‘qualities’ into classes .. like abstract classes.
  • Where an abstract class can have both empty and working/concrete methods, interface methods must all be shells – that is to say, it must be left to the class (using the interface) to flesh out the methods.

Example of a class:

class dog {

function bark() {
echo “yap, yap, yap …”;
}

}

Example of an interface:

interface animal {
function breath();
function eat();
}

Note: the interface’s functions/methods cannot have the details/guts filled in – that is left to the class that uses the interface.

Example of a class using an interface:

class dog implements animal{

function bark() {
echo “yap, yap, yap …”;
}

/* the interface methods/functions must be implemented (given their ‘guts’) in the class */

function breath() { echo “dog is breathing …”;}

function eat() { echo “dog is easting …”;}

}

/*

Remember: when a class uses/implements an interface, the class MUST define all the methods/functions of the interface otherwise the php engine will barf … ‘barf’ is a technical term for: give you an error.

*/

PRIMARY PURPOSES OF AN INTERFACE:

  • Interfaces allow you to define/create a common structure for your classes – to set a standard for objects.
  • Interfaces solves the problem of single inheritance – they allow you to inject ‘qualities’ from multiple sources.
  • Interfaces provide a flexible base/root structure that you don’t get with classes.
  • Interfaces are great when you have multiple coders working on a project – you can set up a loose structure for programmers to follow and let them worry about the details.

WHEN SHOULD YOU MAKE A CLASS AND WHEN SHOULD YOU MAKE AN INTEFACE?

  • If you have a class that is never directly instantiated in your program, this is a good candidate for an interface. In other words, if you are creating a class to only serve as the parent to other classes, it should probably be made into an interface.
  • When you know what methods a class should have but you are not sure what the details will be.
  • When you want to quickly map out the basic structures of your classes to serve as a template for others to follow – keeps the code-base predictable and consistent.

MISC. NOTES:

  • The ‘Holy Grail’ of programming is the reuse of existing code – interfaces play an important role in this.
  • Remember to push up all the code (up the class hierarchy,) to the highest level class. Interfaces help to make this happen.

-

If you find anything to be unclear, please let me know (make a comment) and I will do my best to clarify.

What are database driven websites – podcast.

Saturday, August 26th, 2006

A quick podcast where I explain the basics behind what database driven websites are.

This podcast targets total beginners.

Database Driven Websites Explained.

I did not forget you guys.

Thursday, August 24th, 2006

I been away from making videos for about a week now because of a surprize root canal. This ultra-painful experience (I actually lost 10 lbs!) has prevented me from doing any video work (any work at all,) for last little while.

Let that be a lesson to you all:

  • If you grind your teeth in your sleep (as I do,) get a mouth piece, otherwise you may end up with an abscess tooth or two.
  • Take care of your teeth, otherwise they will come back to byte you … 3 sleepless nights and $1600 for me.

I should be back on the videos within the next couple of days now that the pain has gone.

Reaction to killerphp.com

Wednesday, August 16th, 2006

I’ve received many emails over the last few years, with complaints of how confusing PHP seemed … of how hard the documentation on the web seemed to be.

So I created killerphp.com to help those web designers who seemed to be more inclined to design and not to code.

THE WEBSITE LAUNCHED

I put up the first few videos in July, and at the same time, I let people know on the killersites.com forum about them.

Since then (and to my surprise), in the month and a half that killerphp.com has been online, there has been some interesting things happening:

  • The Digg community seem to like the videos: over 800 diggs last time I checked.
  • The people at Zend Developer zone mentioned an article I wrote and recommended my videos for beginners.
  • Many PHP sites started mentioning killerphp.com.

According to Google, the term ‘killerphp.com’ has appeared in over 18 000 web pages – in less than 2 months! Overall, not a bad reaction in this short a time.

IT’S NOT ALL BERRIES AND CREAM AT KILLERPHP.COM

Generally a positive reaction to the material, I do occasionally get complaints from (what I guess are) experienced PHP programmers, that the videos are too simple or that I’m not the most exciting speaker.

I know I need to keep working on my nerd-speaking skills but too simple!?

… For me, that means I’ve done my job – I’m trying to teach people who don’t know php …

That said, I do appreciate everyone who has taken the time to visit the site and I especially appreciate the feedback, both good and bad. I will try to improve and expand killerphp.com based on what you tell me.

Thanks again,

Stefan Mischook

PHP Video: Processing Forms with PHP – part 1

Sunday, August 13th, 2006

In this video, I review a few key aspects about forms that relate directly to form processing with PHP.

… I cover these three attributes:

  • The ‘action’ attribute
  • The ‘method’ attribute
  • The ‘name’ attribute

In part 2, we will get into practical examples.

PS: these videos are still targeting web designers … so if you are a coder, keep your pants on and don’t start complaining they’re too simple.

I will have more advanced videos and articles coming out soon enough … things like OOP and design patterns to start.

The video:

> Processing Forms

PHP Video – Associative Arrays

Monday, August 7th, 2006

Just released a new video on PHP associative arrays.

Associative arrays are one of the two types of arrays found in PHP and is (in my opinion) one of the most important aspects of the php programming language.

PHP associative arrays are used everywhere and are the underlying mechanism to so many important things in PHP … it is a must know!

> PHP associative array video tutorial

Note: you must do my first video on indexed arrays first

PHP Video – Indexed Arrays

Monday, August 7th, 2006

I just released a new video on the super important indexed array.

PHP indexed arrays are one of the two types of arrays that you’ll find in PHP.

> PHP indexed array video tutorial

3 Categories of Programming Languages

Monday, August 7th, 2006

From Killersites.com blog:

Recently a more practical way of classifying languages has come to my attention – classifying languages by problem-domain or in other words, context.

* System Languages
* Architectural Languages
* Application Languages

I like this list, because it really conveys a sense of practical use for a language. I’ve hammered out the details below

Read the rest here:

3 Categories of Programming Languages

Will Ruby kill PHP?

Monday, August 7th, 2006

With the recent rise in popularity of the Ruby programming language (largely driven by the excellent but not perfect web framework called Rails), I’ve noticed a little fear in the air … fear on the part of some people in the PHP community.

Will Ruby kill PHP?

The short answer is: no.

MY REASONING

Though Ruby and PHP are both scripting languages that make developing web applications much easier than it is, say in the Java world, they are very different beasts … each appeals to a different audience.

RUBY IS ELEGENT BUT COMPLEX

Before I go on, I want to point out that Ruby is a great language and I think it makes perfect sense for PHP developers to learn a little Ruby: it is always a good idea to learn other languages because it will make you a better programmer.

That said, I believe Ruby will not appeal to, or fill the need of most PHP’ers – Ruby can be a little too abstract.

JAVA NERDS LOVE RUBY

Ruby is attracting many from the Java world because it expresses very advanced concepts in a simple syntax – contrast this to Java’s (often times) kludgy and verbose representation.

Ruby appeals to the Java crowd because Java people have been trained to think in terms of large scale enterprise applications – regardless of the size of the project.

… These ‘abstractions’ (generally speaking) lend themselves well to larger projects.

WHY PHP WORKS

PHP is often criticized because it has both a procedural and an object oriented way of doing things. Some people think that this divergence (within the language), takes away from it … I think this is part of its strength!

Objected oriented constructs are great for creating cleaner designs that are easier to maintain and promote the possibility of code reusability. Code reuseability is an often touted advantage of OOP, but from what I’ve seen in the Java world, it is not achieved so often.

With OOP, there is a cost of added complexity and overhead – you simply have to write more code to do things when you do it via OOP.

PHP PROVES THAT NON OO LANGUAGES STILL HAVE THEIR PLACE

I would suggest that the vast majority of PHP work is found in simple projects:

  • Email from a web page.
  • Process a simple form and save to a database.
  • Create a simple store with 10 items.

My point is, that for many PHP projects, OOP may be a little overkill.

WHY RUBY WILL NOT KILL PHP

In Ruby everything is an object (even numbers!) and the core language has very sophisticated constructs that need to be understood to use Ruby effectively – Ruby strength is also its’ weakness.

… I don’t see the majority of PHP users wanting to jump that deep into the world of programmatic abstraction – for most, there is simply no point.

Stefan Mischook

PHP Video – PHP variables part 2

Thursday, August 3rd, 2006

In this video we expand on our exploration of PHP variables. We look at things like:

  • Variable expansion
  • String Concatenation

PHP variables part 2

Once you’ve finished this video, we will be looking at PHP arrays … the key to processing HTML forms.

Evangelizing PHP for web designers

Tuesday, August 1st, 2006

The ‘raison d’être’ for www.killerphp.com is basically to make PHP accessible to the average web designer.

I want to reach people who have more of a design background than a coding/programming background.

TODAY, PHP IS ESSENTIAL WEB DESIGN KNOWLEDGE

I can’t tell you how many times web designers have approached me about doing relatively simple things:

  • Process an html form
  • Install a shopping cart
  • Send an email from a web page

… These common tasks are easily solved with just a little PHP know-how.

The web is far more sophisticated today and as such, web designers have to step up and become more sophisticated themselves.

WHY PHP OVER RUBY OR ASP … ?

Every programming language has something to offer – but today PHP is king for a few reasons:

  • PHP is everywhere – makes it cheap and easy to find php hosting.
  • PHP is powerful – it is a mature language that has all the tools.
  • PHP is easy to use and easy to learn.

When it comes to the types of jobs that most web designers need to tackle (quick shopping carts, process a form etc,) nothing compares to php’s ease of use – it’s simply the best language when you need to bang out something quick.

A COMMENT ABOUT RUBY AND RAILS

Ruby is a great language that is especially appealing to Java nerds like me. It is appealing for many reasons, but one important one is the fact that through a simple, elegant syntax (syntax = code), it can express very advanced programmatic constructs. This strength is also why it is not well suited to the average web designer – it is a little too sophisticated out-of-the-box.

The same can be said for Rails, a web framework (made with and for Ruby) that makes building web applications (websites connected to databases), much easier.

PHP can get very sophisticated as well. But it also has a more approachable side to it, that web designers can much more easily get into.

MOST PHP BOOKS, WEBSITES AND VIDEOS ASSUME TOO MUCH

In my research on php training, I’ve found that the vast majority of books, websites and even videos on php assume the student has a certain knowledge of programming.

This gap in material makes it that much harder for people to learn.

With killerphp.com, I’ve tried to close that gap with easy to follow lessons that help people over that initial learning hump.

Thanks,

Stefan Mischook

PHP Video – PHP includes

Tuesday, August 1st, 2006

These two videos introduce you to one of the most important tools in PHP – PHP ‘includes’.

In a nutshell: PHP ‘includes’ allow you to include/insert code from other pages/documents into your PHP pages.

Web designers familiar with CSS can see this as being like linking to external CSS files. Except with PHP includes, you can insert:

  • HTML/XHTML
  • CSS
  • PHP code

… actually you can insert any type of code.

PHP includes – part 1

PHP includes – part 2

Over 20 minutes of video … let me know what you think!

Thanks,

Stefan Mischook

Top of page  go to top of page