Search This Blog

Loading...
Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

8/22/2012

Heredoc and Nowdoc


Heredoc and Nowdoc (also known as "here document" and "now document") are two alternative representation of strings in PHP (as double quotes and single quotes are).


This post presents these two language features and how to use them.



10/16/2011

Language Constructions

PHP language, like any programming language, is composed by language constructions. Beyond the basic programming structures (conditional, loop, classes syntax, functions syntax, etc), the language has some built-in functions. They are functions compiled in the core language.

8/13/2011

Foreach vs. For

performance

Last year, at a PHP mailing list discussion, I was surprised with the information that the loop structure "for" was faster than "foreach". After, I receive the source of that information: The PHP Benchmark. The site's author said the "for" is faster for write operations, but is slower for reading traveled items. Taking a look at the source-code, I came to the conclusion it was wrong a little strange.

6/26/2011

Error control

Error control is a strategy used to catch situations that blocks a sucessful result of an application operation. This can be viewed in diferent levels of an application. At low level: one function could receive a unespected parameter. At high level, a tool could not accept a specific set of actions from the user.

6/25/2011

Unicode

If you work with Web programming, you might have used character encoding. At begining, computers have used ASCII, that provides basic symbols of English language and some special computer control characters. It was done using 1 byte per character, that could provide 256 characters. In practice, there were only 128 characters, because the first bit was not used.

When other countries starts to use computer, they needed to work with their own language, but ASCII did not provide all language symbols. To resolve that, it was created table maps that associates a symbol with a specific byte. One common charset was ISO-8859-1, that provides Latin symbols. Although, was created many different charsets, incompatible between them and was hard to make programs that suports many languages (many charsets).

To solve this new problem, the Unicode was created. This article shows what unicode is, what are its benefits and how to work with it.

6/14/2011

Scheduled Tasks

Information Systems often have tasks that should be done by schedule. This feature usually is needed because two reasons:

  1. because the task needs to be called at a specific moment;
  2. because the task is too long and it is impractible to take the user waiting while the task does not finish.

6/01/2011

PDO - PHP Data Objects

What is PDO?

PDO (PHP Data Objects) is a PHP module created in the Object Oriented Paradigm, and its goal is to provide a standarized way to PHP connect/comunicate to a Relational Database. It was created in PHP version 5. So, PDO is an interface that defines a set of classes and its method signatures to comunicate with a Database.

Each Database Management System (DBMS) can provide its own driver to PDO. Although PDO provide method signatures, some features can not be supported by some DBMS. So, calling this kind of method may be "useless", depending the driver was used or the DBMS model/version. For example, some engines of MySQL DBMS do not support transactions, so, the method "beginTransation" (that begin a new transation) simply take no effect at this condition.

5/29/2011

Binary Data at PHP Script

There is a feature in PHP that allows to embed data (including binary data) into PHP scripts and it are not parsed by PHP interpreter. It is diferent from exit instruction, that stops script execution, but does not stop the PHP parser. The feature is provided by "__halt_compiler" instruction, that ignores all data after the point it was called.

5/20/2011

PHP Delimiter

Introduction

PHP is an HTML embedded language. This means the PHP code can be inside an HTML, but should have one way to determine whether a stretch of code is PHP or HTML. The way is the use of PHP delimiters. The PHP interpreter is applicable to the stretch of code delimited by the PHP delimiters.

Some programmers use PHP code delimiters, but they do not know about their nuances. Let's see them at this post.

5/16/2011

Layout

Although I like and encourage the use of PHP, I do not like one of its most significant feature: the fact that the language is HTML embedded. It is the language has code delimiter and all code behind the delimiter is considered text blocks, which are sent directly to the standard output (often it is an HTML code).

5/03/2011

Metaprogramming in PHP

With PHP, you can implement a code of a software that can create another code. It is simple, because a PHP script is a text file.

Although, the language allows you to create a script that modify its own behavior at execution time. It can be useful to optimize stretch of code. This feature is based on "eval" PHP function.

4/29/2011

Zend Certified Engineer

Zend Certified Engineer (ZCE) is the consent degree to people who was approved in Zend certification exam. Zend is the company that mantains PHP language and Zend Framework.

We have less than 200 PHP Zend Certified Engineers in Brazil. Although, the degree is one valid way to comprove a certain knowledge about the language. It helps some companies to select candidates.

4/27/2011

Callback

Introduction

Callback is a feature used to pass a function/method by parameter of an other function/method. In general, a function with generic operations receives a callback by parameter and use it to do specific operations. This way, it is possible to use the specific function in diferent places.

4/25/2011

Why did you choose PHP?

PHP for life

Well, I was thinking about: why do I use PHP? I met the language after I have learned a little of Perl, and as soon I saw it I loved it. In few time, I was noting that it is more fantastic then I though. It did "magic" for programmers. I select some features:

  • Consistency;
  • Variable variables;
  • Variable functions;
  • "eval" function to run dinamic code;
  • Magic methods and some interfaces to overload core language actions;
  • Easy casting from data types.

4/23/2011

SELF

Do you know?

Other day I discovered something basic, but that I did not find at PHP documentation. It is one use of reserved word self.

Float Type

The float type is the data type used to represent floating point numbers. In PHP, as in other programming languages, the float type has limits, so precision might be lost. In any case, I will explain that in this article.

4/22/2011

Integer Type

Do you really know the integer type of PHP? It represents a integer number. Well, but we are not here to know what everybody already know. Let's explore something more interesting.