php-general Digest 14 Aug 2009 05:57:42 -0000 Issue 6284

Topics (messages 296758 through 296777):

Re: Design Patterns
        296758 by: Greg Beaver
        296759 by: Ralph Deffke
        296760 by: Ralph Deffke
        296761 by: Ralph Deffke
        296762 by: Jay Blanchard
        296763 by: Robert Cummings
        296764 by: tedd
        296765 by: Ralph Deffke
        296766 by: Nathan Nobbe
        296769 by: Shawn McKenzie
        296773 by: Bastien Koert

design pattern
        296767 by: Ralph Deffke
        296768 by: Robert Cummings
        296770 by: Martin Scotta
        296771 by: Ralph Deffke
        296772 by: Ralph Deffke

session variables - help
        296774 by: Allen McCabe
        296775 by: Ben Dunlap
        296777 by: Allen McCabe

mbstring.func_overload cannot been changed in htaccess
        296776 by: Tony Marston

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 ---
Robert Cummings wrote:
> 
> 
> Martin Zvarík wrote:
>> Ralph Deffke napsal(a):
>>> NO NO NO
>>>
>>> OOP is the best ever inventet !!!!!
>>>
>>> see my comments on this list, I will also come up with an pure oop
>>> opensource OMS very soon.
>>>
>>> I just think a dam big pattern catalog like this one is like an elephant
>>> chacing mice. I mean I can think of customers asking for a
>>> documentation of
>>> course of the page u created for them calling the next day asking
>>> wher the
>>> hell are the code for the page are documented in the 1000 pages of
>>> documentation u had to give them.
>>>
>>> I can think of two of my largest customers with their intranet
>>> application
>>> with 23000 members and more then 50000 hits during working hours where I
>>> startet sweating while figting for every 1ms.
>>>
>>> I'm thinking of people with even more hits a day, they even dont
>>> start using
>>> PHP
>>> so I dont know if thats the right way to blow up with includes  and
>>> thousands of classes.
>>
>> I deeply and completely agree.
> 
> Yes, certainly optimize on an as-needed basis. But well written PHP code
> should certainly scale quite well horizontally. Extremely traffic laden
> websites are quite likely to see a bottleneck at the database before a
> bottleneck in the code.

Hi,

You all should understand that on high traffic sites, C or C++ is far
more frequently used and called "PHP" because they use a whole lot of
custom extensions to speed things up.  In addition, memcached speeds up
database access so much that the speed of PHP starts to matter.  This is
why PHP 5.3.0 is somewhere around 30% faster than any previous PHP
version when running common applications, because the core developers
realized that the base efficiency begins to matter and spent
considerable effort improving basic language performance.

There are a lot of ways to improve PHP's efficiency, and arguing over
whether to use design patterns is not a particularly effective one.
Profiling early and often to understand the slowest portions of your
code is an effective method.  There are many, many talks/videos/etc.
that can be found via google.com which discuss these principles, but
suffice to say that xdebug, APC, and most importantly siege and apache
benchmark are your friends in this endeavor.

For Ralph: it might help you to know that facebook.com improved their
performance by splitting up things into lots and lots of classes, and
using autoload.  I don't have specific details because I don't work
there, but the programmer who coded this solution was telling me the
generalities at php|tek 2 years ago.  The pages that saw improvement
were ones with a large number of possible execution branches in
different requests.  autoload simply reduced the number of needed files
to the bare minimum from a wide variety of choices.

This surprised me, because the prevailing opinion at the time was that
autoload always reduces performance.  The point to take from this story
is that what you think to be true doesn't matter, the only thing is
really understanding where your bottlenecks are by profiling
aggressively, and even more important, why its slow, so you can fix it.

Greg

--- End Message ---
--- Begin Message ---
but what Im asking is that the reality?

go and talk to accountant and tell them after spending soansomuch for the
new site hes has to buy a new server ! what will acountant say, what u
think.

another more important point is in reality u take a project on on a specific
hardware base. lets say it a pretty new server fast a mercedes 500 but not a
ferrari V1.
because of ur great reusable code u do an extra ordinary competitive price
bacause u are ready made that fast, u put it on the server and ? womm
because of thausand of includes and stuff the customer is not happy with the
speed.
what u think who is going to pay the new hardware? or better who is going to
cut down the code.

well its me, because as senior consultant i'm taking over the projects from
young programmers who went out of business because the postulations of the
closed contract put them bankrupt.

THATS THE REALITY so guys tell me on a design pattern frame work what
requirements the server should fullfill that I can astimate if the customers
situation will not put me out of business?


"Robert Cummings" <rob...@interjinn.com> wrote in message
news:4a84400a.9090...@interjinn.com...
>
>
> Ralph Deffke wrote:
> > funny then that I see here serious people discussing the benefit of
> > shortening code and cutting out commends.
> >
> > maby thats a general problem of our society that everybody think higher
> > cheaper faster. this will have a limit guys !!! u can not go smaler then
an
> > atom.
> >
> > funny as well that I make my main money in optimizing code to speed and
low
> > server resources. Im one of the old guys who can do both hardware and
> > software and I'm telling u this is suspect to me. I still can build a
> > computer from board and powersupply upward.
> >
> > looks like that u joung guys got a little dream implementet by ur profs.
Did
> > u know that the industry is complaining that the engeneers coming from
the
> > universities are useless for business? a big complain! the real world is
> > different. Hosting companies will always try to keep a server machine as
> > long as they can, because a paid server DOES MAKE MONEY. so where is
then
> > the cheap and fast server. how many servers out there still running on
PHP4?
> > have u thouhgt about?
> >
> > again, design pattern make sence, but on a companies policy base or on a
> > medium upwards sized project. but there will be more languages be
involved
> > in one company it would be much better to use a language independent
tool.
> >
> > again this is chasing mice with an elephant
>
> Except for incompetent algorithms, it is almost always cheaper to throw
> money at a new server than to have a coder micro optimize his/her code.
> Similarly, it is usually cheaper to throw more hardware at a well
> programmed solution that uses modern programming concepts than to have a
> programmer use the most rudimentary of programming techniques to save on
> cycles.
>
> With respect to why you see "shortening of code and cutting out
> comments", perhaps you are referring to the recent Calendar thread,
> where a bunch of us were just having some good old optimization fun. I
> for one enjoy the occasional diversion of optimizing some code just for
> the sake of optimizing it. Sometimes even, the optimization is even the
> cleanest/most readable solution.
>
> Cheers,
> Rob.
> -- 
> http://www.interjinn.com
> Application and Templating Framework for PHP



--- End Message ---
--- Begin Message ---
Greg I completly aggree, but dont miss the point that I'M adigted to OOP

WHY NOT A FRAMEWORK CLOSER TO THE REAL POINT  CALLED DOM
design pattern for HTML XHTML XML SVG Database conection and retrieving.

WHY CLASSES FOR CALLERS AND RECEIVERS AND INTERPRETERS.

a <div> is it a caller? a receiver?

why there a only dom classes? why not forgetting about the tag shit and a
bunch of classes for it?

well wait I will come up with it if I find ever the time and stop learning
from this list.

I also believe that u can force a good "design patter" by supplying a some
good very well design base classes. I mean talk to an JAVA freak, I dont
think they will come up with that type of framework.

as we just talking about that when can we expect PHP to extend unlimited
classes in one class.

for the newbies following the bullheaded experts fight:
something like this

class wow extents database, users, accessright implements HTML {
}

WHEN

"Greg Beaver" <g...@chiaraquartet.net> wrote in message
news:4a84460d.3080...@chiaraquartet.net...
> Robert Cummings wrote:
> >
> >
> > Martin Zvarík wrote:
> >> Ralph Deffke napsal(a):
> >>> NO NO NO
> >>>
> >>> OOP is the best ever inventet !!!!!
> >>>
> >>> see my comments on this list, I will also come up with an pure oop
> >>> opensource OMS very soon.
> >>>
> >>> I just think a dam big pattern catalog like this one is like an
elephant
> >>> chacing mice. I mean I can think of customers asking for a
> >>> documentation of
> >>> course of the page u created for them calling the next day asking
> >>> wher the
> >>> hell are the code for the page are documented in the 1000 pages of
> >>> documentation u had to give them.
> >>>
> >>> I can think of two of my largest customers with their intranet
> >>> application
> >>> with 23000 members and more then 50000 hits during working hours where
I
> >>> startet sweating while figting for every 1ms.
> >>>
> >>> I'm thinking of people with even more hits a day, they even dont
> >>> start using
> >>> PHP
> >>> so I dont know if thats the right way to blow up with includes  and
> >>> thousands of classes.
> >>
> >> I deeply and completely agree.
> >
> > Yes, certainly optimize on an as-needed basis. But well written PHP code
> > should certainly scale quite well horizontally. Extremely traffic laden
> > websites are quite likely to see a bottleneck at the database before a
> > bottleneck in the code.
>
> Hi,
>
> You all should understand that on high traffic sites, C or C++ is far
> more frequently used and called "PHP" because they use a whole lot of
> custom extensions to speed things up.  In addition, memcached speeds up
> database access so much that the speed of PHP starts to matter.  This is
> why PHP 5.3.0 is somewhere around 30% faster than any previous PHP
> version when running common applications, because the core developers
> realized that the base efficiency begins to matter and spent
> considerable effort improving basic language performance.
>
> There are a lot of ways to improve PHP's efficiency, and arguing over
> whether to use design patterns is not a particularly effective one.
> Profiling early and often to understand the slowest portions of your
> code is an effective method.  There are many, many talks/videos/etc.
> that can be found via google.com which discuss these principles, but
> suffice to say that xdebug, APC, and most importantly siege and apache
> benchmark are your friends in this endeavor.
>
> For Ralph: it might help you to know that facebook.com improved their
> performance by splitting up things into lots and lots of classes, and
> using autoload.  I don't have specific details because I don't work
> there, but the programmer who coded this solution was telling me the
> generalities at php|tek 2 years ago.  The pages that saw improvement
> were ones with a large number of possible execution branches in
> different requests.  autoload simply reduced the number of needed files
> to the bare minimum from a wide variety of choices.
>
> This surprised me, because the prevailing opinion at the time was that
> autoload always reduces performance.  The point to take from this story
> is that what you think to be true doesn't matter, the only thing is
> really understanding where your bottlenecks are by profiling
> aggressively, and even more important, why its slow, so you can fix it.
>
> Greg



--- End Message ---
--- Begin Message ---
Greg I completly aggree, but dont miss the point that I'M adigted to OOP

WHY NOT A FRAMEWORK CLOSER TO THE REAL POINT  CALLED DOM
design pattern for HTML XHTML XML SVG Database conection and retrieving.

WHY CLASSES FOR CALLERS AND RECEIVERS AND INTERPRETERS.

a <div> is it a caller? a receiver?

why there a only dom classes? why not forgetting about the tag shit and a
bunch of classes for it?

well wait I will come up with it if I find ever the time and stop learning
from this list.

I also believe that u can force a good "design patter" by supplying a some
good very well design base classes. I mean talk to an JAVA freak, I dont
think they will come up with that type of framework.

as we just talking about that when can we expect PHP to extend unlimited
classes in one class.

for the newbies following the bullheaded experts fight:
something like this

class wow extents database, users, accessright implements HTML {
}

WHEN

"Greg Beaver" <g...@chiaraquartet.net> wrote in message
news:4a84460d.3080...@chiaraquartet.net...
> Robert Cummings wrote:
> >
> >
> > Martin Zvarík wrote:
> >> Ralph Deffke napsal(a):
> >>> NO NO NO
> >>>
> >>> OOP is the best ever inventet !!!!!
> >>>
> >>> see my comments on this list, I will also come up with an pure oop
> >>> opensource OMS very soon.
> >>>
> >>> I just think a dam big pattern catalog like this one is like an
elephant
> >>> chacing mice. I mean I can think of customers asking for a
> >>> documentation of
> >>> course of the page u created for them calling the next day asking
> >>> wher the
> >>> hell are the code for the page are documented in the 1000 pages of
> >>> documentation u had to give them.
> >>>
> >>> I can think of two of my largest customers with their intranet
> >>> application
> >>> with 23000 members and more then 50000 hits during working hours where
I
> >>> startet sweating while figting for every 1ms.
> >>>
> >>> I'm thinking of people with even more hits a day, they even dont
> >>> start using
> >>> PHP
> >>> so I dont know if thats the right way to blow up with includes  and
> >>> thousands of classes.
> >>
> >> I deeply and completely agree.
> >
> > Yes, certainly optimize on an as-needed basis. But well written PHP code
> > should certainly scale quite well horizontally. Extremely traffic laden
> > websites are quite likely to see a bottleneck at the database before a
> > bottleneck in the code.
>
> Hi,
>
> You all should understand that on high traffic sites, C or C++ is far
> more frequently used and called "PHP" because they use a whole lot of
> custom extensions to speed things up.  In addition, memcached speeds up
> database access so much that the speed of PHP starts to matter.  This is
> why PHP 5.3.0 is somewhere around 30% faster than any previous PHP
> version when running common applications, because the core developers
> realized that the base efficiency begins to matter and spent
> considerable effort improving basic language performance.
>
> There are a lot of ways to improve PHP's efficiency, and arguing over
> whether to use design patterns is not a particularly effective one.
> Profiling early and often to understand the slowest portions of your
> code is an effective method.  There are many, many talks/videos/etc.
> that can be found via google.com which discuss these principles, but
> suffice to say that xdebug, APC, and most importantly siege and apache
> benchmark are your friends in this endeavor.
>
> For Ralph: it might help you to know that facebook.com improved their
> performance by splitting up things into lots and lots of classes, and
> using autoload.  I don't have specific details because I don't work
> there, but the programmer who coded this solution was telling me the
> generalities at php|tek 2 years ago.  The pages that saw improvement
> were ones with a large number of possible execution branches in
> different requests.  autoload simply reduced the number of needed files
> to the bare minimum from a wide variety of choices.
>
> This surprised me, because the prevailing opinion at the time was that
> autoload always reduces performance.  The point to take from this story
> is that what you think to be true doesn't matter, the only thing is
> really understanding where your bottlenecks are by profiling
> aggressively, and even more important, why its slow, so you can fix it.
>
> Greg



--- End Message ---
--- Begin Message ---
[snip]
u can not go smaler then an atom.
[/snip]

Neutrons, electrons, gluons, protons .... particles all smaller than an
atom. There are others if you want to get into a discussion of quantum
physics and mechanics, but we should probably take that discussion
offline.

Many folks here are building enterprise capable applications with PHP,
its OOP capabilities and the afore mentioned design patterns. This level
of application, especially when combined with other technologies (like
the bits that make up AJAX), are much better served by using design
patterns so that consistency, readability and code-ability are enhanced.


You're correct in that the end result is just a text file...but look at
the format of that file output! When those files are handled by the
proper container, such as a web browser or relational database system
they become powerful tools and information.



--- End Message ---
--- Begin Message ---
Ralph Deffke wrote:
but what Im asking is that the reality?

go and talk to accountant and tell them after spending soansomuch for the
new site hes has to buy a new server ! what will acountant say, what u
think.

another more important point is in reality u take a project on on a specific
hardware base. lets say it a pretty new server fast a mercedes 500 but not a
ferrari V1.
because of ur great reusable code u do an extra ordinary competitive price
bacause u are ready made that fast, u put it on the server and ? womm
because of thausand of includes and stuff the customer is not happy with the
speed.
what u think who is going to pay the new hardware? or better who is going to
cut down the code.

well its me, because as senior consultant i'm taking over the projects from
young programmers who went out of business because the postulations of the
closed contract put them bankrupt.

THATS THE REALITY so guys tell me on a design pattern frame work what
requirements the server should fullfill that I can astimate if the customers
situation will not put me out of business?

You could do well to read up on accelerators then since they will save you a large portion of the inclusion/compilation overhead. As a senior consultant you should know that. Everything you've mentioned so far is YOUR reality... possibly shared by others, but so far I'm not seeing too many coming in with the same problem. As a matter of my own discipline, I tend towards shallow class hierarchies and lazy loading of libraries.

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

--- End Message ---
--- Begin Message ---
At 12:32 PM -0400 8/13/09, Robert Cummings wrote:
With respect to why you see "shortening of code and cutting out comments", perhaps you are referring to the recent Calendar thread, where a bunch of us were just having some good old optimization fun. I for one enjoy the occasional diversion of optimizing some code just for the sake of optimizing it. Sometimes even, the optimization is even the cleanest/most readable solution.

Cheers,
Rob.


I agree with Rob.

I would even venture to say that optimization, such as in our calendar exercise, has nothing to do with the speed of the code but rather the cleanest/most readable solution.

One can certainly say "This one runs faster" but what does that matter when we are dealing with a one time operation that takes milliseconds, or less, to run?

The real savings here is seen in maintainability. How well can the next programmer (who might be you) figure out what the code is doing? The time I spend reviewing code is billable. You want to save money, then hire programmers who write clean and easy to understand code. Cryptic crap does not mean that you're a clever programmer, it only shows that you don't know any better.

Cheers,

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
for those of u not being a physician

semiconductors are of pretty big atoms, but this is not the main problem, 
the problem is that u have to cut out structures off these semiconductors
in order to build faster computers this matters.

many physicians believe that we are pretty close to a ultimate limit 
if we dont procees with the *biological* chips we facing a limit soon.

the other point is the cost, faster chips wount be any cheaper in the future
due to very expencive production processes.

So we should start thinking in optimization realy. at least some bewareness
it will not be endless

ralph_def...@yahoo.de




________________________________
Von: Jay Blanchard <jblanch...@pocket.com>
An: Ralph Deffke <ralph_def...@yahoo.de>; php-gene...@lists.php.net
Gesendet: Donnerstag, den 13. August 2009, 20:15:31 Uhr
Betreff: RE: [PHP] Re: Re: Re: Design Patterns

[snip]
u can not go smaler then an atom.
[/snip]

Neutrons, electrons, gluons, protons .... particles all smaller than an
atom. There are others if you want to get into a discussion of quantum
physics and mechanics, but we should probably take that discussion
offline.

Many folks here are building enterprise capable applications with PHP,
its OOP capabilities and the afore mentioned design patterns.. This level
of application, especially when combined with other technologies (like
the bits that make up AJAX), are much better served by using design
patterns so that consistency, readability and code-ability are enhanced.


You're correct in that the end result is just a text file...but look at
the format of that file output! When those files are handled by the
proper container, such as a web browser or relational database system
they become powerful tools and information.


      

--- End Message ---
--- Begin Message ---
On Thu, Aug 13, 2009 at 1:00 PM, Ralph Deffke <ralph_def...@yahoo.de> wrote:

> for those of u not being a physician
>
> semiconductors are of pretty big atoms, but this is not the main problem,
> the problem is that u have to cut out structures off these semiconductors
> in order to build faster computers this matters.
>
> many physicians believe that we are pretty close to a ultimate limit
> if we dont procees with the *biological* chips we facing a limit soon.
>
> the other point is the cost, faster chips wount be any cheaper in the
> future
> due to very expencive production processes.
>
> So we should start thinking in optimization realy. at least some bewareness
> it will not be endless
>
> ralph_def...@yahoo.de


i for one have decided to start off my next server platform for the web,
entirely in assembly ;)

-nathan

--- End Message ---
--- Begin Message ---
Ralph Deffke wrote:
> for those of u not being a physician
> 
> semiconductors are of pretty big atoms, but this is not the main problem, 
> the problem is that u have to cut out structures off these semiconductors
> in order to build faster computers this matters.
> 
> many physicians believe that we are pretty close to a ultimate limit 
> if we dont procees with the *biological* chips we facing a limit soon.
> 
> the other point is the cost, faster chips wount be any cheaper in the future
> due to very expencive production processes.
> 
> So we should start thinking in optimization realy. at least some bewareness
> it will not be endless
> 
> ralph_def...@yahoo.de
> 

My physician had best never mention cutting structures off my semiconductor.

-- 
Thanks!
-Shawn
http://www.spidean.com

--- End Message ---
--- Begin Message ---
[snip]. Cryptic crap does
> not mean that you're a clever programmer, it only shows that you don't know
> any better.
[/snip]

I know people like this


-- 

Bastien

Cat, the other other white meat

--- End Message ---
--- Begin Message ---
so guys

why u don't discuss Martins outcome?
is there no advice, idears?
isn't there a need for it?
nobody want to use it?

I WANT TO LEARN

ralph_def...@yahoo.de



--- End Message ---
--- Begin Message ---
Ralph Deffke wrote:
so guys

why u don't discuss Martins outcome?
is there no advice, idears?
isn't there a need for it?
nobody want to use it?

I WANT TO LEARN

Maybe it's your grasp of the English language, maybe not. But I detect an air of aggression to your posts.

ARE YOU JUST TROLLING?

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

--- End Message ---
--- Begin Message ---
On Thu, Aug 13, 2009 at 4:04 PM, Ralph Deffke <ralph_def...@yahoo.de> wrote:

> so guys
>
> why u don't discuss Martins outcome?
> is there no advice, idears?
> isn't there a need for it?
> nobody want to use it?
>
> I WANT TO LEARN
>
> ralph_def...@yahoo.de
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

I was following the entirely conversation, I must admit I wasn't expecting
such thread.

It is not common to see design patterns applied to PHP applications and, is
more common to don't see PHP applications. They are just scripts. Many
scripts in a simple folder puts together to do the dirty work.

Of course there are many kicking-ass PHP Applications, but they are a
minimum portion compared to old-fashioned scripts.

So, how do we start writing good quality PHP Applications? That's a very
good question, and I don't know the answer, but I think by talking about
design patterns we are in a good way.

It's true that using design patterns the code will run slower, but it'll be
flexible, maintable, and the most important: simple.
After all that's what we are looking for, something really simple that make
our life as developers happier every day. How do you explain the crescent
number of php frameworks for rapid development?

PHP core team has taken OOP seriously.
Do you note the new SPL objects? The core team creates those objects using
many designs patterns.
By example the RecursiveDirectoryIterator and it's family use the decorator
pattern.
Also features such as "late static binding" were added because a design
pattern.

I think there will be some "separation" in the community, those who will
stay using scripts and those who will use heavily OOP. I do not know who the
"dark side" will be, xD


-- 
Martin Scotta

--- End Message ---
--- Begin Message ---
well u got to know me personal, however may be u mix it with sarcasm?
may be I can't express that as good as I want in english.

if u follow the posts didn't some put me in the stupid corner?
I think its legal to ask why the question of Martin are not discussed.

and I still think, my question what he want to accomplish still is legal and
reasonable.

Many posts said, code done with design pattern framework are easy to
maintain and understand.

I ask u; is Martins work easy to understand? he put a lot of effort, but
with even design pattern it comes to the point of a good presentation. not
all people are the top smartest.

as u may have realised, he changed the presentation already and is coming up
with a more overview like documentation.

he is realy working hard, and I can't wait to see what benefit I could have
from his work what size of project it is worth for.

he deserves that design pattern experts comment his work.

ralph_def...@yahoo.de


"Robert Cummings" <rob...@interjinn.com> wrote in message
news:4a846ea7.5010...@interjinn.com...
> Ralph Deffke wrote:
> > so guys
> >
> > why u don't discuss Martins outcome?
> > is there no advice, idears?
> > isn't there a need for it?
> > nobody want to use it?
> >
> > I WANT TO LEARN
>
> Maybe it's your grasp of the English language, maybe not. But I detect
> an air of aggression to your posts.
>
> ARE YOU JUST TROLLING?
>
> Cheers,
> Rob.
> -- 
> http://www.interjinn.com
> Application and Templating Framework for PHP



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

thanks for ur efforts, this is a lot of good work.

for my opinion the start is a bit too much theoretical and valid for all
type of application. In simple words, u are too close to the book.

I would love to have something closer to the purpose of PHP
and its applications.

if u have a look at the SMARTY documentation u have good explanation (and a
bad example by the way concerned oop) what are the real world problem.

When it comes to the final u find the most spagetti code in putting the page
grafic designer toghether with the business logic.

It would be great if this could be put in good oop patterns. As I can not
see that with the little amount of time I have got, p l e a s e tell me what
will come up on this edge?

ralph_def...@yahoo.de


"Martin Scotta" <martinsco...@gmail.com> wrote in message
news:6445d94e0908131322w722a37bbi24983ae143c5d...@mail.gmail.com...
> On Thu, Aug 13, 2009 at 4:04 PM, Ralph Deffke <ralph_def...@yahoo.de>
wrote:
>
> > so guys
> >
> > why u don't discuss Martins outcome?
> > is there no advice, idears?
> > isn't there a need for it?
> > nobody want to use it?
> >
> > I WANT TO LEARN
> >
> > ralph_def...@yahoo.de
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
> I was following the entirely conversation, I must admit I wasn't expecting
> such thread.
>
> It is not common to see design patterns applied to PHP applications and,
is
> more common to don't see PHP applications. They are just scripts. Many
> scripts in a simple folder puts together to do the dirty work.
>
> Of course there are many kicking-ass PHP Applications, but they are a
> minimum portion compared to old-fashioned scripts.
>
> So, how do we start writing good quality PHP Applications? That's a very
> good question, and I don't know the answer, but I think by talking about
> design patterns we are in a good way.
>
> It's true that using design patterns the code will run slower, but it'll
be
> flexible, maintable, and the most important: simple.
> After all that's what we are looking for, something really simple that
make
> our life as developers happier every day. How do you explain the crescent
> number of php frameworks for rapid development?
>
> PHP core team has taken OOP seriously.
> Do you note the new SPL objects? The core team creates those objects using
> many designs patterns.
> By example the RecursiveDirectoryIterator and it's family use the
decorator
> pattern.
> Also features such as "late static binding" were added because a design
> pattern.
>
> I think there will be some "separation" in the community, those who will
> stay using scripts and those who will use heavily OOP. I do not know who
the
> "dark side" will be, xD
>
>
> -- 
> Martin Scotta
>



--- End Message ---
--- Begin Message ---
I am asking a similar question to one I asked yesterday (which received no
answers) with more information in the hopes someone will be kind enough to
guide me.

I have an order form populated with an array (as opposed to a database
table). The user can enter quantities, and the form posts all the
information to the order_process page where the values they entered are
listed for review.

I decided I wanted to allow them to edit quantities before actually
submitting the form (by which I mean before using the mail() function).

I found that $_SESSION is the way to go.

On the order summary page (order_process.php), I start a session and I get
all the POST information via:

[code]

session_start();

extract($_POST);

[/code]

Instead of echoing the quantity values of each item, I populate an input
field with them within an echo:

[code]

//when this function is called, $a is a the quantity variable $show_01_qty
function writeResultRow($a, $b, $c, $d, $e, $f) {
 if($a != '') {
  echo "<tr><input type='text' value=' " . $a . " ' name=' " . $a . " ' id='
" . $a . " ' size='2' /></td>";
  . . .
}
[/code]

Now, in order to update a quantity, the user replaces the quantity in the
input field with the new number, and clicks a submit button which posts to
order_update.php.

I have the following code for order_update.php:

[code]

session_start();
extract($_POST);
foreach ($_POST as $var => $val) {
 if ($val > 0) {
  $_SESSION[$var] = $val;
 } else {
  unset($var);

 }
 header("Location: order_process.php");
}

[/code]

This is not working, however, and it just loads order_process.php with no
values for the varaibles, as if I just refreshed the page with no sessions.

Help please!

--- End Message ---
--- Begin Message ---
>
> I have the following code for order_update.php:
>
> [code]
>
> session_start();
> extract($_POST);
> foreach ($_POST as $var => $val) {
>  if ($val > 0) {
>  $_SESSION[$var] = $val;
>  } else {
>  unset($var);
>
>  }
>  header("Location: order_process.php");
> }
>
> [/code]
>
> This is not working, however, and it just loads order_process.php with no
> values for the varaibles, as if I just refreshed the page with no sessions.


Maybe you left it out but I didn't see any place where you used $_SESSION in
order_process.php. Also, your redirect in order_update.php appears to be
inside your foreach loop, which would definitely mess things right up -- but
maybe that was just a typo in your email?

Otherwise the logic in order_update.php looks OK, but there are a few side
notes that jumped out:

1. I'm not seeing why you used "extract($_POST)" in order_update.php. Right
after the extract() call, you iterate through $_POST with a foreach loop, so
what's the purpose of calling extract()? Is there more code that you left
out?

2. Calling "extract($_POST)" is dangerous. The PHP manual warns against it,
although without giving much of an explanation:

http://us2.php.net/manual/en/function.extract.php

Apart from making it difficult to filter the input you're expecting to see,
"extract($_POST)" also allows a malicious end-user to define any variable of
his choosing and to overwrite any variables that you may have defined in the
script before the extract() call.

I like to use filter_input() to read the values of POST variables.

By much the same token, you'll want to escape $a, etc., in your
writeResultRow() function, with something like htmlentities().

3. Why the "unset($var)" in order_update.php? $var already gets reset each
time foreach iterates. So, calling unset() on it at the end of the loop
doesn't really do much. I'm wondering what you were aiming at there.

Thanks,

Ben

--- End Message ---
--- Begin Message ---
Ben,

First of all, I thank you for your time and help.

My ai with using unset($var) in update_order.php is to set the SESSION
variable for an item to ' ' (empty) so that it would not show up on the
order summary (because my writeResultRow() function will only write a row if
that variable is greater than 0).

I just can't figure out what I'm missing here. Before I received your
response, I made a few changes to my code, which helped streamline the
calculating parts (grabbing values from SESSION instead of POST, and now
when I update order_summary, the values will remain because it pulls them
from the SESSION).

I want to edit the values in the SESSION, so that when update_order.php
redirects to order_process.php, the values are changed, and if applicable,
an item is removed from the html table (if the quantity is less than 1).

Here is some more complete code:

[code = order_process.php]

<?php
session_start();
// POST ALL $_POST VALUES, CREATE AS VARIABLES IN SESSION
foreach($_POST as $k=>$v) {
 $_SESSION[$k]=$v;
}

$thisPage="AFY";  //NAVIGATION PURPOSES
include("afyshows.php"); //CONTAINS ARRAYS FOR SHOW ENTITIES; POPULATES
ORDER FORM
?>

. . .

</p><form name="update" action="update_order.php" method="post" >
 <!-- HIDDEN FORM VALUES FOR SESSION PURPOSES -->
 <input type="hidden" name="School"  id="School" value="<?php
$_SESSION['School']; ?>" />
 <input type="hidden" name="Grade" id="Grade" value="<?php
$_SESSION['Grade']; ?>" />
 <input type="hidden" name="Address" id="Address" value="<?php
$_SESSION['Address']; ?>" />
 <input type="hidden" name="City" id="City" value="<?php $_SESSION['City'];
?>" />
 <input type="hidden" name="State" id="State" value="<?php
$_SESSION['State']; ?>" />
 <input type="hidden" name="Zip" id="Zip" size="9" value="<?php
$_SESSION['Zip']; ?>" />
 <input type="hidden" name="Contact" id="Contact" value="<?php
$_SESSION['Contact']; ?>" />
 <input type="hidden" name="Phone" id="Phone" value="<?php
$_SESSION['Phone']; ?>" />
 <input type="hidden" name="Fax" id="Fax" value="<?php $_SESSION['Fax']; ?>"
/>
 <input type="hidden" name="Email" id="Email" value="<?php
$_SESSION['Email']; ?>" />
. . .

<?php

function findTotalCost($b, $c) {
 $total = $b * $c;
 return $total;
}

function writeResultRow($a, $b, $c, $d, $e, $f) {
 if($a != '') {
  echo "\n<tr>\n\t";
  echo "<td'>".$b."</td><td>".$c."</td><td>".$d."</td>";
  echo "<td>".$e."</td><td>&nbsp;</td><td><input type='text' value='".$a."'
name='".$a."' id='".$a."' size='2' /></td><td>=</td><td>\$".$f."</td>";
  echo "</tr>";
 }
}

//SETS $Total_show_01 to PRICE * QUANTITY
//FORMATS TOTAL
//IF A QUANTITY IS ENTERED, WRITES THE ROW WITH CURRENT VARIABLES
$Total_show_01 = findTotalCost($shows['show_01']['price'],
$_SESSION['show_01_qty']);
$Total_show_01_fmtd = number_format($Total_show_01, 2, '.', '');
writeResultRow($_SESSION['show_01_qty'], $shows['show_01']['title'],
$shows['show_01']['date'], $shows['show_01']['time'],
$shows['show_01']['price'],$Total_show_01_fmtd);

//ABOVE LINES REPEATED FOR ALL 38 ENTITIES (show_01 to show_38)

?>
. . .

<input  name="updates" id="updates"  type="submit" value="Update"/>

[/code]

Now, here is the update_order.php code in entirety:

[code]

<?php
session_start();
foreach ($_SESSION as $var => $val) {
 if ($val == "0") {
  unset($_SESSION[$var]);
 } elseif ($val == '') {
  unset($_SESSION[$var]);
 } else {
  $val = $_SESSION[$var];

 }
}
header("Location: order_process.php");

//NOTICE I FIXED THE LOCATION OF THE header() FUNCTION
//BUT IT STILL DOES NOT UPDATE

?>

[/code]

If you're still with me, I thank you. I removed all the styling elements
from the html to make it easier for you (and me) to see what it says. I have
invested many hours into this, and have generated many many lines of code,
but I hope what I gave you is sufficient, while not being overwhelming at
this hour.

Thank you very much for your help thus far, anything else would be greatly
appreciated.


On Thu, Aug 13, 2009 at 5:56 PM, Ben Dunlap <bdun...@agentintellect.com>wrote:

>
>
>> I have the following code for order_update.php:
>>
>> [code]
>>
>> session_start();
>> extract($_POST);
>> foreach ($_POST as $var => $val) {
>>  if ($val > 0) {
>>  $_SESSION[$var] = $val;
>>  } else {
>>  unset($var);
>>
>>  }
>>  header("Location: order_process.php");
>> }
>>
>> [/code]
>>
>> This is not working, however, and it just loads order_process.php with no
>> values for the varaibles, as if I just refreshed the page with no
>> sessions.
>
>
> Maybe you left it out but I didn't see any place where you used $_SESSION
> in order_process.php. Also, your redirect in order_update.php appears to be
> inside your foreach loop, which would definitely mess things right up -- but
> maybe that was just a typo in your email?
>
> Otherwise the logic in order_update.php looks OK, but there are a few side
> notes that jumped out:
>
> 1. I'm not seeing why you used "extract($_POST)" in order_update.php. Right
> after the extract() call, you iterate through $_POST with a foreach loop, so
> what's the purpose of calling extract()? Is there more code that you left
> out?
>
> 2. Calling "extract($_POST)" is dangerous. The PHP manual warns against it,
> although without giving much of an explanation:
>
> http://us2.php.net/manual/en/function.extract.php
>
> Apart from making it difficult to filter the input you're expecting to see,
> "extract($_POST)" also allows a malicious end-user to define any variable of
> his choosing and to overwrite any variables that you may have defined in the
> script before the extract() call.
>
> I like to use filter_input() to read the values of POST variables.
>
> By much the same token, you'll want to escape $a, etc., in your
> writeResultRow() function, with something like htmlentities().
>
> 3. Why the "unset($var)" in order_update.php? $var already gets reset each
> time foreach iterates. So, calling unset() on it at the end of the loop
> doesn't really do much. I'm wondering what you were aiming at there.
>
> Thanks,
>
> Ben
>
>

--- End Message ---
--- Begin Message ---
I have reported this problem in http://bugs.php.net/bug.php?id=49238. It 
would appear that this option, which was first made available in PHP 4.2.0, 
has been silently dropped. Apparently the decision was made in order to fix 
http://bugs.php.net/bug.php?id=43227, but nothing was explicitly stated in 
the bug report, nor in any release notes, and the documentation still has 
not been updated to reflect this change even after 6 months.

This causes a problem if your site is on a shared server and you don't have 
access to either php.ini or httpd.conf. If this option is turned off by 
default, then how do you turn it on? If it is on by default then how do you 
turn it off? It needs to be turned off for phpMyAdmin otherwise it will 
issue a message warning about possible data corruption.

Should this option be reinstated?

-- 
Tony Marston
http://www.tonymarston.net
http://www.radicore.org 



--- End Message ---

Reply via email to