Follow Slashdot stories on Twitter


Forgot your password?
Slashdot Deals: Cyber Monday Sale! Courses ranging from coding to project management - all eLearning deals 25% off with coupon code "CYBERMONDAY25". ×
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:

You don't have to know how the computer works, just how to work the computer.