Jump to content

Archived

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

eric1235711

define help...

Recommended Posts

This works?

[code]
<?php

if ($test)
  define('TEST', 'test is ok');
else
  define('TEST', 'test is not ok');

echo TEST;

?>
[/code]

of course I will not do some like it, but I just want to know if using define inside a 'if' clause works... ???

Share this post


Link to post
Share on other sites
i need to do me thing like this?

[code]
<?php
define('TEST', 'test is' . ($test? ' ': ' not ') . 'ok');
echo TEST;
?>
[/code]

Share this post


Link to post
Share on other sites
Why dont you try it out for yourself then you'll know. It works for me I get "[i]test is not ok[/i]" message.

Share this post


Link to post
Share on other sites
I´d like to know if php reads all the defines I´ve declared and builds a table with the constants...

If I make ten files with a hundred defines in each, php will build a table with a thousand constants?

Share this post


Link to post
Share on other sites
Huh! With the following code:
[code=php:0]define('TEST', 'test is' . ($test? ' ': ' not ') . 'ok');
echo TEST;[/code]

PHP will define TEST as "test is ok" if the variable $test exists or holds a boolean that is true, is a string or a number etc. If $test was set to a boolean that is false, null or not a string/number etc it'll define TEST as "test is not ok".

When ever you initiate define('VAR_NAME', blah blah) PHP will define the constant VAR_NAME with whats in the secound parameter.

If you have ten files that has 100 defines it will only define 100 constants at a time as you can only run one file at a time, unless you include the other 9 files.

Share this post


Link to post
Share on other sites
Here where I´m working there are is a single functions file called 'general.php' with more than 9000 lines. It also includes other function files...  Lips sealed

There are almost all the functions (not general functions are there too)...

won´t it overcharge the server or will it not do a lot of useless processing? And won´t it put a lot of trash in the server´s memory?

Share this post


Link to post
Share on other sites
Not really no as PHP doesnt load the pages into memery. It just parses php code in the php files. Whne its done parsing the script it releases any memory being used back to the system, this is why variables/constants only work on the file they where created on. PHP only runs on a per-request basis, meaning it'll only run when a client (web browser) request the server for the desiered PHP file.

Share this post


Link to post
Share on other sites

×

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.