PHP Classes

What's this?

Recommend this page to a friend!

      DATA  >  All threads  >  What's this?  >  (Un) Subscribe thread alerts  
Subject:What's this?
Summary:What's this class package about?
Messages:5
Author:Martin Alterisio
Date:2007-04-16 19:04:43
Update:2007-09-15 22:58:22
 

  1. What's this?   Reply   Report abuse  
Picture of Martin Alterisio Martin Alterisio - 2007-04-16 19:04:43
First, sorry for keeping this short. I don't have much time, just wanted to say some things about this before anyone gets the wrong idea.

1 - This idea is still in design.

I needed some help from the PHP community to keep the idea as useful as possible, but I was confronted with much prejudice since I wasn't able to explain my idea clearly. That's why I think that trying to show a bit of working code would help explain the idea, and that's why I published this package here.

2 - This isn't about dumping a whole table or db into arrays and working with them, this is about objects acting LIKE arrays.

I guarantee the efficiency would be as much as any other regular ORM, but without having to write mapping XMLs or having to rewrite your db as classes.

3 - Yes, it's possible to make array operations that actually read or write a DB.

At least in PHP5 is possible without much jeopardy. I wouldn't even propose this idea if I didn't find it viable.

4 - I'll be posting what my ideas are for the design of these classes, where I'm having some trouble to decide which way would be best to provide an useful abstraction, which doesn't require many constrains on the db structure.

I'll try to be more detailed, more organized, and provide example code, which I didn't in the thread I started in the PHP general list, even if this slows downs the design process a bit.

I'll really appreciate any thoughts you may have.

  2. Re: What's this?   Reply   Report abuse  
Picture of Martin Alterisio Martin Alterisio - 2007-07-16 18:05:21 - In reply to message 1 from Martin Alterisio
You may have noticed by now that I decided to follow my intuition and start the design on that only. I'm really sorry I wasn't able to engage the whole community in the design process, this would have taken to much time, and the experience I had trying to get some help and opinion on this in the PHP general mailing list, was so fruitless and frustrating that I had to make the choice of imposing only my ideas on the design.

Anyway, I think the results were as satisfactory as they could have been, and, at least, the project seems to be on the right course. There's still much to be done, and any comments and suggestions will be highly appreciated.

  3. Re: What's this?   Reply   Report abuse  
Picture of Matt Smith Matt Smith - 2007-09-05 04:07:32 - In reply to message 2 from Martin Alterisio
I've been 'subscribed' to this project for well over a month and it just gets better and better. The only thing that bothers me, and I know you're working on it, is the lack of control for SELECT'ing data. I've got my own version of Justin Vincent's ezSQL where I've done something similar to what you've done, except your idea totally blows mine out of the water.

I think I'll be doing some work of my own on the project and see what happens. If its any good, maybe we can merge our changes..

Excellent work, Martin!

  4. Re: What's this?   Reply   Report abuse  
Picture of Martin Alterisio Martin Alterisio - 2007-09-05 05:11:15 - In reply to message 3 from Matt Smith
Thank you very much for your support! As you can imagine indeed I'm working on giving more power to the user in deciding how and what is selected on the database, without losing the abstraction layer that provides the array access, which is proving to be really difficult (one bad design choice can become a real nuisance in the future).

I recently found out that one decision I made was not the best, and could bring some problems in the future. Sometimes you use an int pk instead of the real pk for performance, and usually the real pk ends out being a unique key. I wished to make the library recognize this and use the real pk instead, but I left out the possibility to use the int pk if the value provided is numeric. The problem is I was pushing the problem of preventing the end-user from trying to access by the int field when he should only be using the char field...

In the end I decided to leave only the access through the unique field, if available, and devised an alternative to make the table index through the int pk: $DB['table']->byXXXX, where XXXX is the name of the pk in camel notation. This decision wasn't taken lightly, since I began to consider the possibilities of extending this ->byXXXX feature. In short, I'm thinking of providing through this special property a way to access partial views of the table, according the value of one field, and pinpointing a row by accessing each field of a key.

Still, I'm working on ways to select ranges, and mapping table relationships, so that have a complete set of possibilities on the conditions of the select.

----

As I began this project I first envisioned it as simpler or more natural way to interact with a db without having to go low level with sql, I thought "hey everyone knows how to use an array! I don't have to teach them that!". But now it has come to my attention that there is another powerful property of the arrays, and that is that they are the most used structures in traditional algorithmic solutions. If you have a classic graph algorithm working on arrays, why not use it with objects that actually belong in a db? It may not be the fastest, but we can just bring that old graph algorithm for making tournament fixtures and make it work...

Taking in consideration that this package could be also useful in working strictly with algorithmics, I seeing that this could also be a nice feature for a db abstraction, I've been working on abstracting sql data types and providing features to catch errors of computation that may arise using these (invalid data, overflows, etc) which are not usually captured nor taken into full consideration, but are necessary for debugging algorithms.

Still, a mechanism is provided to disable this feature (since its overhead its quite considerable) for those who prefer performance over data integrity.

Anyway, it's late here. I'll post more on the new version tomorrow or the day after.

  5. Re: What's this?   Reply   Report abuse  
Picture of Martin Alterisio Martin Alterisio - 2007-09-15 22:58:22 - In reply to message 1 from Martin Alterisio
Sorry I wasn't able to write anything else about the new version. I've been busy on some other stuff. I still have to upload the new documentation, a new file release in sourceforge, and update freshmeat... I'll get to it, soon... I hope... =)