Jump to content


Photo

define help...


  • Please log in to reply
7 replies to this topic

#1 eric1235711

eric1235711
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts
  • LocationSão Paulo - Brazil

Posted 15 September 2006 - 01:30 PM

This works?

<?php

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

echo TEST;

?>

of course I will not do some like it, but I just want to know if using define inside a 'if' clause works... ???
Programming is like building your own universe...
But let me ask you something:
Your world... It´s cool? Or it sucks?

#2 eric1235711

eric1235711
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts
  • LocationSão Paulo - Brazil

Posted 15 September 2006 - 01:35 PM

i need to do me thing like this?

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

Programming is like building your own universe...
But let me ask you something:
Your world... It´s cool? Or it sucks?

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 15 September 2006 - 01:36 PM

Why dont you try it out for yourself then you'll know. It works for me I get "test is not ok" message.

#4 eric1235711

eric1235711
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts
  • LocationSão Paulo - Brazil

Posted 15 September 2006 - 01:38 PM

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?
Programming is like building your own universe...
But let me ask you something:
Your world... It´s cool? Or it sucks?

#5 eric1235711

eric1235711
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts
  • LocationSão Paulo - Brazil

Posted 15 September 2006 - 03:55 PM

help...
Programming is like building your own universe...
But let me ask you something:
Your world... It´s cool? Or it sucks?

#6 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 15 September 2006 - 04:36 PM

Huh! With the following code:
define('TEST', 'test is' . ($test? ' ': ' not ') . 'ok');
echo TEST;

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.

#7 eric1235711

eric1235711
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts
  • LocationSão Paulo - Brazil

Posted 15 September 2006 - 05:14 PM

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?
Programming is like building your own universe...
But let me ask you something:
Your world... It´s cool? Or it sucks?

#8 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 15 September 2006 - 05:22 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users