- Author: György Fekete
- Published on August 7th, 2009
So do you want to convert an array to an object for no particular reason?
I worked on a project where I wrote this code. The class below eats up to 2536 bytes of memory, but make sure to read this whole post for the surprise!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
| class array_to_object
{
function __construct($data=null, &$node=null)
{
foreach ( $data as $key => $value )
{
if ( is_array($value) )
{
if (! $node )
{
$node =& $this;
}
$node->$key = new stdClass();
self::__construct($value,$node->$key);
}
else
{
if (! $node )
{
$node =& $this;
}
$node->$key = $value;
}
}
}
} |
The code above creates a new stdClass, PHP’s built-in class and uses it to create properties out of the array’s keys inside the object.
Basically, this $arr['hello'] = ‘world!’; becomes this $arr->hello = ‘world!’;
Now, here comes the surprise!
Hardcore one liner
1
2
3
4
| function array2obj($data)
{
return is_array($data) ? (object) array_map(__FUNCTION__,$data) : $data;
} |
The function above does the same thing, except it uses 72 bytes of memory and it’s much more optimized!
- Author: György Fekete
- Published on July 13th, 2009
Since the official release of PHP 5.3 many developers want to test the new features out, but still don’t want to mess with the old PHP installation. Same thing goes for me, I don’t want to mess up my existing PHP installation yet, but eager to test namespaces, late static binding and closures.
So let’s create a virtual development environment using the latest software bundles.
Continue Reading
- Author: György Fekete
- Published on December 12th, 2008
As you may know, inheriting from multiple objects in PHP 5 is impossible, because of the language restrictions. You can’t write code such as this:
1
2
3
| class Child extends Mother, Father {
//class code here
} |
Continue Reading
- Author: Stelian Mocanita
- Published on December 5th, 2008
The usage of sessions is the php developer’s most common use since we constantly need to transact data from step to step. An average programmer would say that using sessions is far more secure than letÃs say cookies since the session data is server side data, thing that is partially correct.
The fact that the attacker can’t have a clear look at what and where you store comes to your advantage but a more dedicated attacker can go a bit further than this presumption.
A must have for the attacker in a session hijack is the Session Identifier so he can impersonate the attack. Let’s presume for example that you have your website hosted on a shared hosting on which PHP is installed as an Apache module, thing that makes session files belong to the web user, in other words: accessible.
Continue Reading
- Author: György Fekete
- Published on November 13th, 2008
CSRF stand for Cross Site Request Forgeries, it’s a method that allows an outside attacker to send malformed HTTP requests to a website, but from a victim’s computer. In this case the actual victim is the accomplice to this attack.
Stronger security measures must be implemented in order to avoid CSRF attacks, and to make sure the website and it’s users are not vulnerable.
To better understand CSRF attacks let’s look at an example. Let’s say you’re signed in to Facebook, you browse around and in the mean time you open a new window or a new tab and visit another site. It’s a typical scenario. Now, your still signed in at Facebook on the other tab and you visit a site where there’s a CSRF attack implemented. Now the CSRF site actually could send out spam to your Facebook friends or even delete your account, all this using your credentials, because a session is saved when you logged into Facebook (remember, on the other tab).
Continue Reading
- Author: György Fekete
- Published on November 10th, 2008

This tutorial will cover the basic syntax and common features of PHP. It assumes that you already know what is a server-side scripting language and you have already installed and set up PHP on your development machine.
If you want to learn PHP, you should start by reading this article, which covers the absolute basics of PHP programming language.
Continue Reading
- Author: György Fekete
- Published on November 5th, 2008

Bootstrapping means that every server request are funneled through a single (or a few) PHP file. This file will be the “bootstrapper” of our application. It will help instantiate objects that are needed by every page in general such as starting a session, connecting to a database, defining constants and default variables, etc.
Continue Reading
- Author: György Fekete
- Published on November 4th, 2008
We can say that PHP is a mature language with lot’s of useful, but potentially dangerous features. The rapid growth of the language and the dynamic nature of the Web let people easily create dynamic web pages without any prior knowledge in computer science or the architecture of the Internet.
In this tutorial we’ll have a look at 4 important PHP security measures that you should implement in order to develop a safer website.
Continue Reading
- Author: György Fekete
- Published on November 1st, 2008

Copyright: John Boston
The process of backing up sensitive information became more and more important as software and hardware failures tend to happen more often with complex web applications.
If you’re never had any information loss, subversion repository corruption, etc. then consider yourself lucky. You don’t want to be in the shoes of a web developer that just lost a year of work, source code snippets, mockups, designs, proprietary code, etc.
If you don’t put your work in subversion repositories then it’s time to do it and let’s see how to write a PHP shell script to make the backup almost a transparent task.
Continue Reading