Become a fan of Slashdot on Facebook


Forgot your password?
User Journal

Journal Sloppy's Journal: Circular dependencies in three languages 1

Here are six files for ya, showing a problem in 3 different scripting languages. What will they do?
--------- test1.php:
require 'test2.php';

define('SOMECONSTANT','hello world');

function foo() {
                return SOMECONSTANT;

echo foo(); echo "\n";

--------- test2.php:
require_once 'test1.php';

echo foo(); echo "\n";
import test2

SOMECONSTANT='hello world'

def foo():
                return SOMECONSTANT

print foo()
import test1

--------- test1.rb:
require 'test2.rb'

SOMECONSTANT='hello world'

def foo

puts foo()
--------- test2.rb:
require 'test1.rb'

puts foo()
Ok, scriptfiends, predict the output of these three commands:
php -q -f test1.php
ruby test1.rb

and then do some pasting and try it out. Match your predictions?

The PHP one bit me pretty hard today.

This discussion has been archived. No new comments can be posted.

Circular dependencies in three languages

Comments Filter:

"Of course power tools and alcohol don't mix. Everyone knows power tools aren't soluble in alcohol..." -- Crazy Nigel