php-general Digest 22 Jul 2010 15:14:37 -0000 Issue 6859

Topics (messages 307082 through 307096):

Re: XML DOM
        307082 by: Benjamin Hawkes-Lewis

Does class length slow down performance
        307083 by: Sebastian Ewert
        307084 by: Ashley Sheridan
        307086 by: Sebastian Ewert
        307087 by: Jay Blanchard
        307088 by: Sebastian Ewert
        307090 by: Peter Lind
        307092 by: Sebastian Ewert
        307093 by: Peter Lind

Re: Question about SQL and Graph nodel trees
        307085 by: Tommy Pham

PHP database interface layer
        307089 by: Marc Guay
        307091 by: Peter Lind
        307095 by: Nathan Nobbe
        307096 by: Marc Guay

Video lessons
        307094 by: Jordan Jovanov

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
On 21 Jul 2010, at 19:32, Ben Miller wrote:
> Problem:
> 
> If street2 (or any other field) has no value, PHP is outputting the XML node
> as <street2 />, which is producing a JS error when I try to call:
> 
> <script type="text/javascript">..
> 
> street2 = x[i].getElementsByTagName("street2")[0].childNodes[0].nodeValue;
> 
>                ...</script>   (Because the requested node has no
> .nodeValue, I'm assuming???)
> 
> 
> 
> Question:
> 
> Can I tell PHP to output the XML node as <street2></street2> instead of
> <street2 /> so that JS sees that the object has a value, but the value is ""
> (blank)?

"<street2>foo</street2>" is syntax that means a "street2" element with one 
child node: text node "foo".

"<street2></street2>" and "<street2 />" are different syntax that mean the same 
thing: a "street2" element with no child nodes.

Your JS property lookup fails because the "street2" element has no child nodes. 
Rather than changing your XML serialization to have some sort of opaque 
meaning, why not do one of the following in your JS?

   1. Test to see if the element in question has any child nodes before 
attempting to access the first one:

   if (x[i].getElementsByTagName("street2")[0].childNodes.length > 0) ...

   2. Use the "textContent" and "innerText" properties to get the text of 
all/any child nodes.

--
Benjamin Hawkes-Lewis

--- End Message ---
--- Begin Message ---
Hi,

I'm developing an joomla component and my helper an user classes are
crowing bigger and bigger. The helper class is for static use only.

Does class size decrease performance of my php scripts, even for static
usage?
Is there a general rule when to split a class to keep performance up?

Thanks for reply,
Sebastian


--- End Message ---
--- Begin Message ---
On Thu, 2010-07-22 at 10:49 +0200, Sebastian Ewert wrote:

> Hi,
> 
> I'm developing an joomla component and my helper an user classes are
> crowing bigger and bigger. The helper class is for static use only.
> 
> Does class size decrease performance of my php scripts, even for static
> usage?
> Is there a general rule when to split a class to keep performance up?
> 
> Thanks for reply,
> Sebastian
> 
> 


How big roughly are we talking here? The larger a script or class is,
the more memory this uses per instance. Out of the box, PHP doesn't have
a way to share the memory space of libraries and classes, so creating
massive scripts for a website is not a great idea.

The typical approach is to break classes down into blocks such that you
need only include per script what you actually need to run that script.

For example, having a full class dedicated to user management would need
somewhere to create a list of users. Now it doesn't make sense to
include this user management class each time you want to create a list
of users, so you could split that method off into a different class
where it can easily be shared without every script loading in lots of
unnecessary code.

That's a very simple example, but it can help beforehand if you sketch
out exactly what you need to do, and then break it down into logical
classes like that. Maybe look at some UML software to help you with
this?

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
Ashley Sheridan wrote:
> On Thu, 2010-07-22 at 10:49 +0200, Sebastian Ewert wrote:
> 
>> Hi,
>>
>> I'm developing an joomla component and my helper an user classes are
>> crowing bigger and bigger. The helper class is for static use only.
>>
>> Does class size decrease performance of my php scripts, even for static
>> usage?
>> Is there a general rule when to split a class to keep performance up?
>>
>> Thanks for reply,
>> Sebastian
>>
>>
> 
> 
> How big roughly are we talking here? The larger a script or class is,
> the more memory this uses per instance. Out of the box, PHP doesn't have
> a way to share the memory space of libraries and classes, so creating
> massive scripts for a website is not a great idea.
> 

The user object contains 850 Lines and about 50 functions. It also
implements 2 table-objects (DB Tables).
The helper class contains 500 Lines.

> The typical approach is to break classes down into blocks such that you
> need only include per script what you actually need to run that script.
> 
> For example, having a full class dedicated to user management would need
> somewhere to create a list of users. Now it doesn't make sense to
> include this user management class each time you want to create a list
> of users, so you could split that method off into a different class
> where it can easily be shared without every script loading in lots of
> unnecessary code.

Thats exacty the point. In my user class I have functions whitch return
object-lists of diffrent users or strings with html-form elements for
managing this user account.

But if I put all these in a helper class I would anyway need to
implement the user object there, because of the other getter functions
(getUserName etc.) and the table-objects.

I always thought this would be less effective, because I have more
instances of objects.

Thanks,
Sebastian



--- End Message ---
--- Begin Message ---
[snip]
Thats exacty the point. In my user class I have functions whitch return
object-lists of diffrent users or strings with html-form elements for
managing this user account.

But if I put all these in a helper class I would anyway need to
implement the user object there, because of the other getter functions
(getUserName etc.) and the table-objects.

I always thought this would be less effective, because I have more
instances of objects.
[/snip]

Sounds like a major refactoring is in order, how reusable is your class?

There is not enough room in this e-mail to cover the basic and
intermediate practices of OO design but it sounds like you may need to
re-think your design. Does this class do one thing and only one thing?
Does it do it really well? 

Just from what I am reading I see that we have a user class
(getUserName) and that class returns lists of users? It sounds as if to
me that the user class talks not only about a single user, but perhaps
all of the users (object lists of different users). 

On the surface that sounds like to classes to me, a user class and a
class to manipulate said users.



--- End Message ---
--- Begin Message ---
Jay Blanchard wrote:
> [snip]
> Thats exacty the point. In my user class I have functions whitch return
> object-lists of diffrent users or strings with html-form elements for
> managing this user account.
> 
> But if I put all these in a helper class I would anyway need to
> implement the user object there, because of the other getter functions
> (getUserName etc.) and the table-objects.
> 
> I always thought this would be less effective, because I have more
> instances of objects.
> [/snip]
> 
> Sounds like a major refactoring is in order, how reusable is your class?
> 
> There is not enough room in this e-mail to cover the basic and
> intermediate practices of OO design but it sounds like you may need to
> re-think your design. Does this class do one thing and only one thing?
> Does it do it really well? 
> 

Thanks for your advice. I know that I have to go much deeper into
programm design. I would appreciate if you could send me some links with
practial examples. I've only read some theoretical and very general
stuff about it and cannot link everything to the real world.

> Just from what I am reading I see that we have a user class
> (getUserName) and that class returns lists of users? It sounds as if to
> me that the user class talks not only about a single user, but perhaps
> all of the users (object lists of different users). 
> 

That was just to generalize things. My user class only returns
informations for one user. These informations are values of db-fields or
generated html strings.

But other classes like my message class have functions that return lists
of instances of their own class. From what you've written I think its
better to extract these functions into helper classes.

But if you want to get all messages that refer to one specific msg its
better to leave that function in the message class, isn't it? Or if you
want to get a list with all friends of a specific user?(friends are not
implemented yet)

> On the surface that sounds like to classes to me, a user class and a
> class to manipulate said users.
> 
> 

But back to my first Problem:

Is a class with 850 lines to long?
If it is should I take all the html genarating functions and put them in
a helper class?
If I do so and there is no way to call those functions without
initalizing the main user object, will there still be an increase of
performance?

Thanks,
Sebastian


--- End Message ---
--- Begin Message ---
On 22 July 2010 15:27, Sebastian Ewert <seb2...@yahoo.de> wrote:
> Jay Blanchard wrote:
>> [snip]
>> Thats exacty the point. In my user class I have functions whitch return
>> object-lists of diffrent users or strings with html-form elements for
>> managing this user account.
>>
>> But if I put all these in a helper class I would anyway need to
>> implement the user object there, because of the other getter functions
>> (getUserName etc.) and the table-objects.
>>
>> I always thought this would be less effective, because I have more
>> instances of objects.
>> [/snip]
>>
>> Sounds like a major refactoring is in order, how reusable is your class?
>>
>> There is not enough room in this e-mail to cover the basic and
>> intermediate practices of OO design but it sounds like you may need to
>> re-think your design. Does this class do one thing and only one thing?
>> Does it do it really well?
>>
>
> Thanks for your advice. I know that I have to go much deeper into
> programm design. I would appreciate if you could send me some links with
> practial examples. I've only read some theoretical and very general
> stuff about it and cannot link everything to the real world.
>
>> Just from what I am reading I see that we have a user class
>> (getUserName) and that class returns lists of users? It sounds as if to
>> me that the user class talks not only about a single user, but perhaps
>> all of the users (object lists of different users).
>>
>
> That was just to generalize things. My user class only returns
> informations for one user. These informations are values of db-fields or
> generated html strings.
>
> But other classes like my message class have functions that return lists
> of instances of their own class. From what you've written I think its
> better to extract these functions into helper classes.
>
> But if you want to get all messages that refer to one specific msg its
> better to leave that function in the message class, isn't it? Or if you
> want to get a list with all friends of a specific user?(friends are not
> implemented yet)
>
>> On the surface that sounds like to classes to me, a user class and a
>> class to manipulate said users.
>>
>>
>
> But back to my first Problem:
>
> Is a class with 850 lines to long?
> If it is should I take all the html genarating functions and put them in
> a helper class?
> If I do so and there is no way to call those functions without
> initalizing the main user object, will there still be an increase of
> performance?
>

It's unlikely to cause you performance problems unless you've got a
huge amount of traffic - and then you could probably fix your problems
easier than refactoring classes.

Personal anecdote: I've worked on classes longer than 3K lines with no
marked performance problem. That doesn't mean I recommend it, though:
bigger classes are a pain to maintain as you loose overview of what's
in the class.

Regards
Peter

-- 
<hype>
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
</hype>

--- End Message ---
--- Begin Message ---
Peter Lind wrote:
> 
> It's unlikely to cause you performance problems unless you've got a
> huge amount of traffic - and then you could probably fix your problems
> easier than refactoring classes.
> 
> Personal anecdote: I've worked on classes longer than 3K lines with no
> marked performance problem. That doesn't mean I recommend it, though:
> bigger classes are a pain to maintain as you loose overview of what's
> in the class.
> 
> Regards
> Peter
> 
So you think that a length of 850 lines won't lead to a performance
problem?

The site is not online yet. I just wanted to know when to split a class
and if there are performance problems with to long classes.

Thanks,
Sebastian


--- End Message ---
--- Begin Message ---
On 22 July 2010 15:49, Sebastian Ewert <seb2...@yahoo.de> wrote:
> Peter Lind wrote:
>>
>> It's unlikely to cause you performance problems unless you've got a
>> huge amount of traffic - and then you could probably fix your problems
>> easier than refactoring classes.
>>
>> Personal anecdote: I've worked on classes longer than 3K lines with no
>> marked performance problem. That doesn't mean I recommend it, though:
>> bigger classes are a pain to maintain as you loose overview of what's
>> in the class.
>>
>> Regards
>> Peter
>>
> So you think that a length of 850 lines won't lead to a performance
> problem?
>
> The site is not online yet. I just wanted to know when to split a class
> and if there are performance problems with to long classes.

No, I don't think there will be problems. I also think the only way
you'll ever find out whether it *will* be a problem in your system is
by testing.

Regards
Peter

-- 
<hype>
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
</hype>

--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Tim Gallagher [mailto:tgallag...@danati.com]
> Sent: Wednesday, July 21, 2010 12:49 PM
> To: Andrew Ballard
> Cc: php-gene...@lists.php.net
> Subject: RE: [PHP] Question about SQL and Graph nodel trees
> 
> Thank you for the informaiton.  I did see that code but it looks like it is
> formatted for MSSQL and was unable to get it to work for Mysql.
> 
> Tim
> 

@Tim, You'll have to migrate the stored procedures (SP) from MSSQL to MySQL 
(aka stored programs).  Each DBMS have their own way of implementing the SP.
http://dev.mysql.com/doc/refman/5.1/en/stored-programs-views.html

@Andrew, interesting link! Thanks!

Regards,
Tommy

> ________________________________________
> From: Andrew Ballard [aball...@gmail.com]
> Sent: Wednesday, July 21, 2010 11:40 AM
> To: Tim Gallagher
> Cc: php-gene...@lists.php.net
> Subject: Re: [PHP] Question about SQL and Graph nodel trees
> 
> On Wed, Jul 21, 2010 at 11:04 AM, Tim Gallagher <tgallag...@danati.com>
> wrote:
> > I cannot be the only one that is having this problem, what are you using for
> DAG (Direct Acrylic Graph)?  I need to have a mesh node edge graph and am
> having trouble with this?  I see that Neo4j has a rest server and I can do 
> this
> in Java but I want to do it in PHP with a MYSQL or postgresql.  If you are 
> doing
> something like this, can you please tell me how you are doing this.  I can do 
> a
> relationship with a parent child or a nested tree, but I need to do a DAG.
> >
> > Thanks for the help,
> > timgerr
> >


> 
> A basic approach would be to use two tables - one to store the nodes and
> second table to store the edges between the nodes. As far as traversing the
> graph, the best approach I have seen expands this a bit to store the full
> transitive closure of the graph, rather than just the direct edges:
> 
> http://www.codeproject.com/KB/database/Modeling_DAGs_on_SQL_DBs.a
> spx
> 
> It is written for SQL Server, but the idea works OK (and I successfully 
> tested it
> once) in MySQL. (I imagine the same would be true for PostgreSQL.)
> 
> The idea is to store the transitive closure (every possible path) of the 
> entire
> graph. For instance, if you have a basic graph
> 
> A -> B -> C -> D
> 
> it stores these paths:
> 
> A -> B
> B -> C
> C -> D
> A -> C
> B -> D
> A -> D
> 
> The obvious downside is that edge table can get incredibly large depending
> on the nature of the graph you are modeling. (The article provides much
> more detail.) I did, however, import a good chunk of an Active Directory tree
> (just users and groups, not the full list of
> attributes) into this pattern just to test the concept, and I found that in 
> that
> case the size of the transitive closure table did not get out of hand.
> 
> 
> Andrew
> --
> PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
> http://www.php.net/unsub.php



--- End Message ---
--- Begin Message ---
Hi everyone,

I've built a fairly large normalized database schema for a project.
This is fun for me as I like thinking about how everything is
interconnected.  Foreign keys are all set up, many-to-many tables are
go, etc, and so on.   But now it's time to create an interface between
that database and the website using PHP.  I've searched the web and
this is obviously a very common problem with many solutions, but I
can't help but feel that all of the logic I've built into the database
is worth nothing once I start coding.  I found this
article/presentation that essentially sums up my frustration:
http://mag-sol.com/talks/lpm/2006/orm/.  Up until now I've been
working on smaller projects with only a few tables that don't really
relate to each other, and have found this tool
(http://www.ricocheting.com/code/php/mysql-database-class-wrapper)
very handy for the reasons he explains, but I'm looking for something
a little different.  I've looked at RedBean and it seems pretty handy,
but it also requires me to redefine all of the foreign keys I've
already defined, which is annoying.  Any hope of something like

// Get company where name='Widgets Inc.' or id=1 or....
$company = $db->get_company("name='Widgets Inc.'");

// Get all clients joined to the company
$clients = $company->get_clients();

// Get all projects joined to the client
$projects = $clients->get_projects();

?

--- End Message ---
--- Begin Message ---
On 22 July 2010 15:35, Marc Guay <marc.g...@gmail.com> wrote:
> Hi everyone,
>
> I've built a fairly large normalized database schema for a project.
> This is fun for me as I like thinking about how everything is
> interconnected.  Foreign keys are all set up, many-to-many tables are
> go, etc, and so on.   But now it's time to create an interface between
> that database and the website using PHP.  I've searched the web and
> this is obviously a very common problem with many solutions, but I
> can't help but feel that all of the logic I've built into the database
> is worth nothing once I start coding.  I found this
> article/presentation that essentially sums up my frustration:
> http://mag-sol.com/talks/lpm/2006/orm/.  Up until now I've been
> working on smaller projects with only a few tables that don't really
> relate to each other, and have found this tool
> (http://www.ricocheting.com/code/php/mysql-database-class-wrapper)
> very handy for the reasons he explains, but I'm looking for something
> a little different.  I've looked at RedBean and it seems pretty handy,
> but it also requires me to redefine all of the foreign keys I've
> already defined, which is annoying.  Any hope of something like
>
> // Get company where name='Widgets Inc.' or id=1 or....
> $company = $db->get_company("name='Widgets Inc.'");
>
> // Get all clients joined to the company
> $clients = $company->get_clients();
>
> // Get all projects joined to the client
> $projects = $clients->get_projects();
>
> ?
>

Have you looked at things like Doctrine2?

Regards
Peter

-- 
<hype>
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
</hype>

--- End Message ---
--- Begin Message ---
On Thu, Jul 22, 2010 at 7:35 AM, Marc Guay <marc.g...@gmail.com> wrote:

> Hi everyone,
>
> I've built a fairly large normalized database schema for a project.
> This is fun for me as I like thinking about how everything is
> interconnected.  Foreign keys are all set up, many-to-many tables are
> go, etc, and so on.   But now it's time to create an interface between
> that database and the website using PHP.  I've searched the web and
> this is obviously a very common problem with many solutions, but I
> can't help but feel that all of the logic I've built into the database
> is worth nothing once I start coding.  I found this
> article/presentation that essentially sums up my frustration:
> http://mag-sol.com/talks/lpm/2006/orm/.  Up until now I've been
> working on smaller projects with only a few tables that don't really
> relate to each other, and have found this tool
> (http://www.ricocheting.com/code/php/mysql-database-class-wrapper)
> very handy for the reasons he explains, but I'm looking for something
> a little different.  I've looked at RedBean and it seems pretty handy,
> but it also requires me to redefine all of the foreign keys I've
> already defined, which is annoying.  Any hope of something like
>
> // Get company where name='Widgets Inc.' or id=1 or....
> $company = $db->get_company("name='Widgets Inc.'");
>
> // Get all clients joined to the company
> $clients = $company->get_clients();
>
> // Get all projects joined to the client
> $projects = $clients->get_projects();
>
> ?


i recommend propel

http://www.propelorm.org/

-nathan

--- End Message ---
--- Begin Message ---
> i recommend propel
> http://www.propelorm.org/

This looks hopeful.  I'd checked it out before but for some reason
lumped it in with all of the other half-baked tools that didn't do
what I wanted, but even that basic example seems to cover most of what
I want.

Thanks for the suggestions.

Marc

--- End Message ---
--- Begin Message ---
Hello

Im thing that I'm little layse, Do you somebody know PHP VIDEO LESSONS?

Thanks a lot.

--- End Message ---

Reply via email to