Archive for the ‘php’ Category

Array dereferencing support in PHP 5.4.0

http://www.razvantudorica.net/07/array-dereferencing-support-in-php-5-4-0/

Advertisements

Cannot redeclare geoip_country_code_by_name

Today I had this error on my Ubuntu Linux box

Fatal error: Cannot redeclare geoip_country_code_by_name()

The reason was that I have geoip extension enabled in my PHP configuration and also I used the geoip.inc file from maxmind.com.

The solution is very simple.

http://www.razvantudorica.net/03/cannot-redeclare-geoip_country_code_by_name/

How To – Activate PHP in public_html for Ubuntu 10

It seems it is a bug (I didn’t investigate too much) in Ubuntu 10.x related to PHP files in userdirs.

On my box I have Ubuntu 10.10, Apache/2.2.16 (Ubuntu) and PHP 5.3.3-1. Everything worked fine except the PHP files from ~userdir. Instead to parse these files, the web server send them directly to the browser which open the “save as” window.

The problem is in /etc/apache2/mods-enabled/php5.conf file.

<ifmodule mod_userdir.c>
<directory /home/*/public_html>
php_admin_value engine Off
</directory>
</ifmodule>

These lines should be commented:

# <ifmodule mod_userdir.c>
# <directory /home/*/public_html>
# php_admin_value engine Off
# </directory>
# </ifmodule>
 

A simple MVC framework

I will describe in the following post a (very) simple MVC framework. You can download the source code from here or can make a copy from bitbucket repository.

As you can see, we have the following folders:

web: here resides your public files (images, css, and index.php)
app: here you can find application files: models, views, controllers (MVC)

Continue reading

Singleton Pattern

This pattern is probably one of the most simple and used pattern. As php manual says: The Singleton pattern applies to situations in which there needs to be a single instance of a class. The most common example of this is a database connection. Implementing this pattern allows a programmer to make this single instance easily accessible by many other objects.

There are tons of information about this pattern over the Internet so I let you google for it.

You can find a singleton implementation in Simple MVC framework example.

Public, Private, and Protected in PHP

or how to manage access to your classes.

In PHP there are three levels of access for properties and methods from within a class: public, private, and protected.

Public access is the default setting for method and for properties.

  • Public properties and methods can be accessed from any context.
  • Private methods and properties can ONLY be accessed from within the enclosing class. The subclasses have no access to them.
  • Protected methods and properties can be accessed from within the enclosing class and from subclasses.

According with Zend Coding Standards, variables that are declared with the “private” or “protected” modifier, the first character of the variable name must be a single underscore.

eg: private $_myVar;