background preloader

PHP

Facebook Twitter

Reflection in PHP. Reflection is generally defined as a program's ability to inspect itself and modify its logic at execution time.

Reflection in PHP

In less technical terms, reflection is asking an object to tell you about its properties and methods, and altering those members (even private ones). In this lesson, we'll dig into how this is accomplished, and when it might prove useful. A Little History At the dawn of the age of programming, there was the assembly language.

A program written in assembly resides on physical registers inside the computer. As with any cool toy, use reflection, but don't abuse it. As higher-level programming languages (like C) came along, this reflectivity faded and disappeared. Today, most programming languages can use reflection. A Simple Example Reflection is prevalent in PHP. And: In this code, we have a direct call to a locally initialized variable with a known type. Next, modify Nettuts, like so: Now, Nettuts has absolutely no relation to the Editor class. Object Member Information The Callback. Aspect-Oriented Programming in PHP with Go!

The concept of Aspect-Oriented Programming (AOP) is fairly new to PHP.

Aspect-Oriented Programming in PHP with Go!

DateTime. If you need DateTime::createFromFormat functionality in versions <5.3.0 releases you might use the following basic class which can also be combined with Tom's class.

DateTime

It should work for most basic formats, however you should improve this function if you need more complex formats. <? Phpclass DateClass extends DateTime{ public function getTimestamp(){ return $this->format ("U"); } List of Supported Timezones. Classes and Objects. Model View Controller(MVC) in PHP Tutorial. The model view controller pattern is the most used pattern for today’s world web applications.

Model View Controller(MVC) in PHP Tutorial

It has been used for the first time in Smalltalk and then adopted and popularized by Java. At present there are more than a dozen PHP web frameworks based on MVC pattern. Despite the fact that the MVC pattern is very popular in PHP, is hard to find a proper tutorial accompanied by a simple source code example. That is the purpose of this tutorial. The MVC pattern separates an application in 3 modules: Model, View and Controller: The model is responsible to manage the data; it stores and retrieves entities used by an application, usually from a database, and contains the logic implemented by the application.

The above figure contains the MVC Collaboration Diagram, where the links and dependencies between figures can be observed: Our short php example has a simple structure, putting each MVC module in one folder: Controller Our Controller class has only one function and the constructor. Viewbook.php. PHP Login script tutorial. We have a login form in step 2, when a user submit their username and password, PHP code in checklogin.php will check that this user exist in our database or not.

PHP Login script tutorial

If user has the right username and password, then the code will register username and password in the session and redirect to "login_success.php". If username or password is wrong the system will show "Wrong Username or Password". How To Write A Simple PHP/MySQL Web Service for an iOS App. If you're new here, you may want to subscribe to my RSS feed or follow me on Twitter.

How To Write A Simple PHP/MySQL Web Service for an iOS App

Thanks for visiting! Web Services Rule! As an iPhone/iPad developer, it can be really useful to be able to write your own simple web services that integrate with your apps. For example, you may wish to display some news updates that come from your web server, and display it on startup. Or perhaps store some user data “in the cloud”. In this first tutorial in this two-part series, you’ll go step-by-step through the process of creating a simple web service, based on a promo code system I included in my latest app, Wild Fables.

To run through all of the steps on this tutorial, you’ll need a web server with MySQL and PHP. Php Master: Write Cutting Edge Code - Lorna Mitchell, Davey Shafik, Matthew Turland. PHP Sessions. Prevent Duplicate Form Submission Learn how to use PHP sessions to prevent duplicate form submission or re-submission.

PHP Sessions

PHP MySQL Login Script Login and user authentication is the most common feature in any dynamic website. Date. Most spreadsheet programs have a rather nice little built-in function called NETWORKDAYS to calculate the number of business days (i.e.

date

Monday-Friday, excluding holidays) between any two given dates. I couldn't find a simple way to do that in PHP, so I threw this together. It replicates the functionality of OpenOffice's NETWORKDAYS function - you give it a start date, an end date, and an array of any holidays you want skipped, and it'll tell you the number of business days (inclusive of the start and end days!) Between them. I've tested it pretty strenuously but date arithmetic is complicated and there's always the possibility I missed something, so please feel free to check my math.

The function could certainly be made much more powerful, to allow you to set different days to be ignored (e.g.