Jump to content

Drupal-Help needed-A newbie


aileia

Recommended Posts

I am using drupal 4.7x.

I write the following code in the blog entry

<?php

$life=42;

function meaningOfLife() {

global $life;

  print "The meaning of life is $life<br />";

}

meaningOfLife();

 

?>

 

and then select php code as input format.

The result turn out to be

 

The meaning of life is

 

which is wrong, apparently, what i want is

 

The meaning of life is 42.

 

This is an example given in php.net so it should be correct. Moreover since the function is executed, it confirms I installed php. However I can't define the variable $life in the function. It is printing the text, so it is calling the function however it is not calling the variable. Can anyone tell me what went wrong?

 

Link to comment
https://forums.phpfreaks.com/topic/90667-drupal-help-needed-a-newbie/
Share on other sites

Not enough to pin point whats causing it mate sorry :(

Can I suggest you add the code to a test.php file on your server and make sure that works ? as long as that works you can be 100% sure its drupal having some effect.

If not it could be something to do with your php.ini setup.

globals are bad at the best of times, pass this variable into your function. eg;

 

<?php
$life=42;
function meaningOfLife($v) {
   print "The meaning of life is $v";
}
meaningOfLife();

?>

 

I would assume drupal uses eval or something to evaluate this code, and obviously globals won't work for whatever reason.

 

As for this....

My bad noticed another mistake -

 

replace this

$life=42;

 

 

with this

$life = '42';

 

Integers are not to be quoted.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.