# Can PHP be used in Ruby?

**URL:** <https://www.ruby-forum.com/t/can-php-be-used-in-ruby/70663>\
**Category:** Ruby\
**Created:** [October 1, 2006, 6:41pm UTC](https://www.ruby-forum.com/t/can-php-be-used-in-ruby/70663 "2006-10-01T18:41:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [October 1, 2006, 6:41pm UTC](https://www.ruby-forum.com/t/can-php-be-used-in-ruby/70663/1 "2006-10-01T18:41:15Z")

</div>

Can I run some PHP code in Ruby, and access the variables?

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [October 1, 2006, 6:49pm UTC](https://www.ruby-forum.com/t/can-php-be-used-in-ruby/70663/2 "2006-10-01T18:49:15Z")

</div>

removed\_email\_address@domain.invalid wrote:

> Can I run some PHP code in Ruby, and access the variables?

No.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [October 1, 2006, 7:53pm UTC](https://www.ruby-forum.com/t/can-php-be-used-in-ruby/70663/3 "2006-10-01T19:53:24Z")

</div>

quoth the James B.:

> removed\_email\_address@domain.invalid wrote:
> 
> > Can I run some PHP code in Ruby, and access the variables?
> 
> No.

Not strictly no:

irb(main):001:0\> foo = `php foo.php`  
=\> “some value\n”

where foo.php is:

\<?php $foo = "some value"; echo $foo; ?\>

Though the real question is why you would want to do something as  
ridiculous  
as this?

OP: Explain what you are trying to accomplish and someone here can  
probably  
give you some good advice…

-d

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [October 1, 2006, 11:23pm UTC](https://www.ruby-forum.com/t/can-php-be-used-in-ruby/70663/4 "2006-10-01T23:23:40Z")

</div>

quoth the David V.:

> > =\> “some value\n”
> 
> That’s not quite running PHP code in ruby, is it?
> 
> David V.

in/from potayto/potahto

Don’t get me wrong, I am certainly not endorsing that sort of thing but  
it is  
a way to get a php variable’s value into Ruby…

-d

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [October 1, 2006, 8:07pm UTC](https://www.ruby-forum.com/t/can-php-be-used-in-ruby/70663/5 "2006-10-01T20:07:25Z")

</div>

darren kirby wrote:

> quoth the James B.:
> 
> > removed\_email\_address@domain.invalid wrote:
> > 
> > > Can I run some PHP code in Ruby, and access the variables?  
> > > No.
> 
> Not strictly no:
> 
> irb(main):001:0\> foo = `php foo.php`  
> =\> “some value\n”

That’s not quite running PHP code in ruby, is it?

David V.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [October 2, 2006, 6:44am UTC](https://www.ruby-forum.com/t/can-php-be-used-in-ruby/70663/6 "2006-10-02T06:44:08Z")

</div>

On 10/1/06, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Can I run some PHP code in Ruby, and access the variables?

Not really with stock Ruby. However along with JRuby there is a  
project to run PHP on the JVM. A design goal for all the languages now  
being supported is that there should be as little barrier to calling  
from one to another as possible. It’s reasonable to think that as  
JRuby and the PHP implementation (Quercus) mature, the boundary  
between the two will lessen. Indeed, we’ve already discussed with some  
of the Javascript-oriented folks at Sun how to make Javascript and  
Ruby work well together in the JVM. Interoperability will happen, so  
you may get what you’re looking for in the near future.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [October 2, 2006, 12:07am UTC](https://www.ruby-forum.com/t/can-php-be-used-in-ruby/70663/7 "2006-10-02T00:07:43Z")

</div>

Actually, you can use pretty much anything you want …

I tend to start up an external process running whatever ( perl, python,  
php, java, C++, whatever ) … and have it run a XMLRPC engine …

Then I just send code that means something to that engine …

So, with everything but C++ you can just do evals on the xmlrpc side …  
( in java I recommend beanshell ) … let it do what it needs to do …  
and return a string or integer or whatever … ( usually if I need a  
complex data structure I pass YAML back and forth since there are YAML  
engines for most any programming language you could want to use ) …

Anyways … that’s how I go about it … it definately lets you use Ruby  
as glue or as your controller …

… hope that helps.

jd

On Sun, 01 Oct 2006 14:22:01 -0700, darren kirby
