Jump to content

Do Constants Also Have Global And Local Scopes?


50r

Recommended Posts

Hey freaks i want to be sure on this, do are constants binded to global and local scopes like valuables? i see one code of my friend using constants in a class method but i dont see where he declairs them global. but they are defined from an included config file.

Here's a little snippet to show scope constant scope

 

<?php
define ('ACONST', 42);

if (defined('BCONST'))
   echo BCONST . ' BCONST exists 1<br />';
else
   echo 'BCONST not yet defined<br />';

echo test();

if (defined('BCONST')) echo BCONST . ' (BCONST exists globally now)<br />';

function test()
{
   define('BCONST', ACONST * 2);
   return BCONST . ' BCONST from function<br />';
}
?>

RESULTS
------------------------------
BCONST not yet defined
84 BCONST from function
84 (BCONST exists globally now)

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.