Victor's Blog about PHP, Zend Framework & Cake PHP

This blog is about PHP in general. It tackles various topics related to the language itself especially at the OOP level, discusses various topics related to Zend Framework and shares my experience with Cake PHP. I believe that mastering technology is heavily based on one's ability to discuss its details and share knowledge with others. Technology is a wide wild world after all!

Learning PHP for Beginners

Printable Version

victor | 11 February, 2017 13:52

So you are a student who just finished learning the basics of programming and you are so interested about learning PHP. Your friends told you how cool PHP is and I am pretty sure they showed you a bit of their work. You are curious as to how to learn it quickly to be able to start doing the same.

Well here is the deal to get this done :)

In this post, I will tackle the best way to learning PHP as a student. When I use the term student, I refer to a person who is still learning, has 1-2 free hours per day and willing to spend them learning new stuff. I also refer to a person who has enough curiosity and is willing to master technology rather than just get things done from a practical perspective.

 (More)

How-To Validate / Sanitize Data in PHP

Printable Version

victor | 07 December, 2012 08:50

In this post, I will tackle a very important (and usually ignored topic) when programming in PHP.

Data validation and sanitization is not only important at the business level, but also very important at the security level since this is where most attacks usually take place especially when dealing with SQL injection and Cross-Site Scripting attacks.

 (More)

How-To Set the Time to be Synchronized in CentOS / Linux?

Printable Version

victor | 03 December, 2012 12:27

First, we will install NTP Daemon which will keep the server time in sync continuously.

yum install ntp
chkconfig ntpd on

Then, we will set the time for the first time from the command prompt.
ntpdate pool.ntp.org

Then, we will start the NTP daemon to keep the time in sync continuously.
/etc/init.d/ntpd start

Then, we will sync the current date / time to the server's hardware clock.
This can be done as follows:

hwclock --systohc

Please note that to check your current date, you simply need to execute the 'date' command
date

How-To Write Valid Facebook Meta Tags in XHTML

Printable Version

victor | 10 November, 2012 08:08

It is a well-known fact that Facebook tags cause W3C Validator errors. This type of errors also cause browsers to delay (slightly) the display of pages while trying to fix such errors.

The trick below causes browsers to ignore this type of tags while, at the same time, allows Facebook to properly retrieve them when needed.

 (More)

PHP Function Overloading

Printable Version

victor | 16 November, 2010 07:24

All Object Oriented languages (or almost all of them) support function overloading where programmers are allowed to define multiple functions with the same name but with separate "function signatures". A function signature is usually the number of parameters, the order of parameters and / or the type of parameters.

For example, in Java, you are allowed to define the following:

public void testFunction (int x) { ... }

public void testFunction (int x, int y) { ... }

public void testFunction (int x, double y) { ... }

By defining the above, the Java Virtual Machine will automatically invoke the appropriate function once called based on the number and type of parameters given. For example, invoking

testFunction (2);

will automatically invoke the first function while invoking

testFunction (2, 3.1);

will automatically invoke the third function.

PHP, on the other hand, does not have support for function overloading yet. Defining the same function more than once with a different number of paramters will surely (so far) generate an error at the parser level.

It is still possible to simulate function overloading in PHP using parameters default values. Upon function definition, simply provide default values to parameters as follows:

function testFunction ($a = false, $b = false, $c = false) { .... }

By doing so, you will be defining a function that takes 3 arguments ($a, $b, and $c) whose default value is false.

Within the function body, you will then simply check whether the value of the parameter that is being passed is still false and act accordingly.

Remember, though, that PHP provides automatic data type conversion. In other words, if the value of $b is 0 (Zero) and you check whether $b is false using the equality operator (==), you will get a true value returned. As such, remember to use the data typed equality operator (===) instead of the normal operator (==).

 

PHP Autoloading

Printable Version

victor | 22 February, 2010 09:20

Autoloading is the process of automatically loading classes when needed wthout having to go through the traditional include() and require() directives. This helps PHP developers work without having to worry about whether the class that they need has already been loaded or not.

To achieve this, PHP 5 provides the __autoload() magic method that is called automatically whenever a class / object is being referenced while not being defined. If a definition exists for that class, the magic method will not be invoked. If a definition does not exist, the __autoload() method will be invoked before giving up and generating a warning / error message.

So how does auto loading work in examples?

 (More)

What is PHP, Zend Framework and Cake PHP?

Printable Version

victor | 21 February, 2010 01:33

My first really mini-article will be simply a definition of the 3 topics behind this blog.

PHP is a widely used, general-purpose web scripting language that is embedded into the HTML source document and interpreted by a web-server integrated PHP processor module.

The name "PHP" is a recursive acronym that stands for "PHP Hypertext Preprocessor". PHP code can be also processed by an interpreter application in command-line mode to perform desired operating system operations. It may also function as a graphical application through the integration of a windowing toolkit (like PHP GTK).PHP is available as a processor for most modern web servers and as standalone interpreter on most operating systems and computing platforms.

Zend Framework (ZF) is an open source, object-oriented web application framework implemented in PHP 5. ZF is a use-at-will framework.

There is no single development paradigm or pattern that all Zend Framework users must follow, although ZF does provide components for the (Model View Controller paradigm) MVC, Table Data Gateway, and Row Data Gateway design patterns. Zend Framework provides individual components for many other common requirements in web application development.

CakePHP is an open source web application framework for producing web applications. It is written in PHP and is compatible with PHP 4 and PHP 5.

CakePHP makes it easier for the user to interface with the database with the active record pattern. It also encourages the use of the MVC architectural pattern and provides cool features like integrated CRUD for datasource interaction, application scaffolding, built-in validation, data sanitization, and internationalization and localization, various behaviors, components and helpers to minimize development time, as well as unit testing using the SimpleTest framework.

PHP, Zend Framework and CakePHP are all available through open-source licenses that allow for their free usage (although dontaion is highly recommended to maintain them) and that provide complete access to the source code behind them. More detailed topics pertaining to specific characteristics of these technologies will be provided in future articles.

1 2  Next»
 
Accessible and Valid XHTML 1.0 Strict and CSS