views:

45

answers:

1

Hi all!

I am working with javascript pseudoclasses in the sense of:

class Foo
---->getName()
---->setName()
---->....

So i can have collections of them to operate with in client calculations. But, there is some way to handle them "as is" in php?

in other words, pass it like an object where I could do a call to getName, for example.

Thanks in advance, Ragnagard :D

+1  A: 

No. You cannot run JavaScript code in PHP.

You do have some alternatives, though:

  1. Reflection: You could create the class in PHP, and use PHP's reflection capability to generate the JavaScript code. Depending on the kind of class this could get very tricky very fast.
  2. Not using PHP. There are some alternatives to using JavaScript as a server-side scripting language. In this case, you could share parts of your JS code both on the client and the server.
Jani Hartikainen
well, sorry for the missunderstanding.PHP is needed in this project, and javascript is used just to control the interface a bit or doing some Ajax animations over the data. Not wanting to execute code but most directed to gather the information, like you can do with JSON from php to javascript.So i am looking for the opposite direction, from a javascript pseudoclass.
Ragnagard
Like Jani says, you can't run JavaScript in PHP. There's no opposite of JSON. You have to use $_GET or $_POST to fetch individual values, and reconstruct the objects "manually" in your PHP code.
Magnar
well then, seems that only JSON reverse operation (stringify) will be needed, send data in a POST request, and then JSON-decode on PHP.It's ok but could be better xD.thanks for getting the point ;)
Ragnagard