On Mon, 2011-04-04 at 08:03 -0500, Jay Blanchard wrote:

> [snip]
> Short answer : yes.
> Medium answer : probably, but really yes.
> Long answer : unless you are providing some sort of mechanism to hold
> the current state of PHP, eject the required JS code to get a value
> from the client and return it to the server which then recreates the
> working environment and carries on execution (try debugging THAT),
> then almost certainly.
> [/snip]
> So dynamically generated pages by PHP shouldn't spit out any JS of any
> type?

That's not what he said. PHP can more than adequately output Javascript
(or any other kind of output you can think of really, such as XML, PDF,
images, etc), it's just generally most people use it to output HTML.
Quite often it's easiest when passing data from PHP to Javascript to do
it by outputting Javascript code directly, but it does help to separate
PHP from the client-side. So rather than think of embedding PHP in an
HTML file, it's really the other way around, because as soon as you take
an HTML file and include PHP, the whole thing is parsed by php the
program on the server, which then outputs HTML to Apache, rather than
Apache just grabbing the plain HTML and sending it to the client.

Because web servers (typically) don't parse Javascript code, PHP knows
nothing about the functions you've declared in it, even if PHP was
responsible for outputting the Javascript code itself, in much the same
way that you wouldn't expect PHP to output CSS and know whether your
browser has correcly applied the styles or not. Everything that happens
on the client-side is outside of PHP and the server.


Reply via email to