Popular Posts

 How to Convert Array Notation to Object Notation

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!

 Urgent Patch for Visual Studio and Other Tools

Microsoft released two out-of-cycle patches on July 27, 2009, one for IE and one for Visual Studio. Microsoft normally only release patches on the second Tuesday of the month. Only urgent patches are issued outside this cycle, and these patches should normally be installed ASAP.

Continue Reading

 8 More Useful Tools for ASP.NET

This time I want to deal with some other useful tools for ASP.NET developers that I have used on a regular basis. Again, before using for commercial purposes, please check the license information.

Continue Reading

 Useful tools on CodePlex and elsewhere

In this my first article for this website, I want to deal with some of the many useful projects on codeplex.com for ASP.NET developers. Before using for commercial purposes, please check the license information.

Continue Reading

 Focus On

 Creating a PHP 5.3 Virtual Development Environment

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

 An Introduction to MVC

MVC, or Model-View-Controller, is an architectural pattern used in software development. Although it’s been around for several decades, it has gained popularity recently as the crux of rapid development frameworks such as Ruby on Rails, CakePHP, Monorail, and JavaScriptMVC.

The aim of MVC is to promote good programming practices and code reuse by separating a web application into three layers: data, presentation, and the interaction between the two. By separating these elements from each other, one can be easily updated without affecting the others.

Continue Reading

 PHP 5.3

The PHP 5.3 stable release is imminent.

“PHP 5.3.0 is a newly developed version of PHP featuring long-awaited features like namespaces, late static binding, closures and much more.”

It is scheduled on June 30th

(via) Lukas Smith

 Site Update

Thank you everyone who read, contributed, and subscribed on Server-Side Magazine.
As you discovered, SSM is struggling a little bit, but I still have plans with it.

I’m considering to re-brand the website, creating a new theme and writing more interesting articles.

So stay tuned!

 SQL Query Tester v0.1

SSM presents another great tool called SQL Query Tester.

It is created for web developers who are working / testing SQL queries a lot. The nice thing about this tool is that it gets the query results via AJAX, so you don’t have to refresh the page, it has a SQL syntax highlighter and a basic profiling tool.

It is written in PHP and jQuery, using ADOdb as a database abstraction layer and CodePress for the SQL editor.

It’s completely open source, you can find it at: code.google.com/p/sql-query-tester

If you want to contribute or suggest features don’t hesitate to comment here or on the project’s groups page.

Screenshot:

SQL Query Tester Screenshot