Edit: The PHP and Dart script will run on client-side.
I will run a php script on my page load. Then i would like to access the php functions within dart scope. Is it possible or should i migrate everything to dart?
To be more specific;
- I am tring to develop a facebook application (with facebook php sdk),
- I have written several ‘Hello, World!’ web applications,
- and that is all experience i got for now.
Thanks in advance.
No. There is no clean way to communicate between Dart and PHP. With client-side Dart, you have the normal problem of client-side vs server-side scripting. With server-side Dart, as far as I can tell (researching with google), there is no interoperability between the two.
Client-side vs Server-side Scripting
In web development, there are two main classes of programming languages: server-side and client-side. Server-side languages are run on the web server and determine the response that the web server sends to reply to the HTTP request. Client-side languages are run on the client (read, browser) and manipulate the DOM, etc in the browser.
Calling server-side code from client-side code would be like running a command on your friends computer from your computer without ssh. Directly calling a server-side function from a client-side language (
function my_client_func() { my_server_func(); }) is impossible.Workarounds
There are a number of ways to achieve this functionality. Two are AJAX and WebSockets.
AJAX allows you to make HTTP requests asynchronously and act on the data when it arrives. You could create a mechanism to retrieve data from the server via special web pages, or something similar. You could make a page called
facebook.com/apps/yourapp/function.phpand call it with parameters likename=myFuncitonName&var1=something&var2=else, etc (function.php?name=myFunction...).WebSockets allows you to create a full-duplex TCP-esque. You could create a PHP WebSocket server that would call functions based on received WebSocket messages, though this could create a security hole.
Server-side Language Interoperability
Some server-side languages provide mechanisms to interoperate with other such languages. Dart does not seem to provide a mechanism to call PHP code.
Workarounds
Dart does provide a mechanism to run processes in the form of the Process class. You could use the Process class to call the PHP interpreter.
Dart does provide interoperablility with C. Using Native Extensions, Dart code can call C functions. Based on this question, C code can call PHP functions.