Acumen Development

  • Acumen Development
  • Acumen Systems
  • Acumen Third Sector
  • About Us
  • Websites
  • Web Applications
  • Branding
  • Support
  • Contact Us

Vector for php, surely not?

recent news

  • Wordpress and Subversion
    Leo Brown, 1st June

  • Working with Corrupt Subversion Repositories
    Leo Brown, 20th January

  • Integrating with Web1.0 Service Providers
    Leo Brown, 4th June

  • WordPress Text Replacement Plugin
    Leo Brown, 14th February

  • Direct Email Reception
    Leo Brown, 2nd January

Project Request Form

Download a project request form here

Vector for php, surely not?

February 21, 2008
categories: Open Source
tags: performance, php, vector

Ok before you try to hit me let me explain. This is not just a boring Object Orientated wrapper for storing PHP object in an array. It’s a multi-indexed, self sufficient class.

Too many times I’ve seen my code swell with foreach loops, looking for elements with a certain property, or to call a function of each object in an array. Additionally making sure the keys of an array match one particular property and stay in sink with them. So to try and side step all these I’m started Vector, I’m sure others have done similar, but reinvention is one of the fun things about being a programmer (and one of the few things which make it similar to being an artist).

So here’s how you use Vector currently:

<?php

require_once('Vector.class.php');
require_once('User.example.class.php');


//initialize a Vector and add a index that uses the username field of each object entered into the array
$users=new Vector();
$users->addIndex('username');


//add two objects of class User into the vector
$users->addObject($frank=new User('frank.n.stein','monster'));
$users->addObject($vlad=new User('count.dracula','vampire'));


//call the checkpassword method of the object whose username is count.dracula
if($users->exists('username','count.dracula') && $users->username['count.dracula']->checkPassword('vampire'))
{
echo 'password correct!';
}
else
{
echo 'password false';
}
?>

I hope to include more features later. But it’s a start.


3 Responses to “Vector for php, surely not?”

  • Dr. Evil on February 1st, 2009 at 3:50 pm

    Where is the source code for your Vector class.

  • Sir Happy on September 16th, 2009 at 5:35 pm

    Never existed, just pretending i guess, here is my Vector.class.php impl

    $obj = new Person();
    $people = new Vector();
    $people->add($obj);
    if($obj->exists($obj))
    echo ‘I exist!’;

  • Storage Cheetham Hill on July 21st, 2010 at 8:06 am

    That is a great, thanks a lot to post this.


Leave a Reply