This will occur because it is not including the other file and precisely because it is hiding the error message makes it difficult to know the reason for the problem. Avoid using the @
, in fact never use, much less if it is in a development phase, after all if it is developing something which the reason to hide the error message, that are there to help you?! I recommend you read publication on this subject.
When you do:
@Chat_Scripts;
You remove the Notice: Use of undefined constant Chat_Scripts - assumed 'Chat_Scripts' in /in/meLso on line 3'
, this occurs twice. That’s why he gives a echo
of Chat_Scripts
, because it assumes that it would echo 'Chat_Scripts'
.
Removing the error message does not fix the error, put the @
is not the solution. What happens is that constant cannot be accessed, as said in the message, to resolve you must use include()
between the files or put all the information in one file, so just join the two pieces of code you have in one.
For example:
C:.
├───inc
│ chat.php
│
└───public_html
index.php
There are two folders, in the hierarchy shown above, each folder with a different file.
The C:/servidor/inc/
chat.php
will possess:
const CHAT_ENABLE = 1;
const CHAT_HTML = [
1 => '<embed src="http://www.xatech.com/web_gear/chat/chat.swf" quality= "high" width= "500" height= "300" name= "chat" FlashVars="id=158331371&rl=Brazilian" align="middle" allowscriptaccess= "sameDomain" type= "application/x-shockwave-flash" pluginspage= "http://xat.com/update_flash.shtml" /></embed>',
0 => '<div class="info-box"> O Chat se encontra Desativado</div>'
];
The C:/servidor/public_html/
index.php
possesses:
include('../inc/chat');
echo CHAT_HTML[ CHAT_ENABLE ];
The include
will include the archive chat.php
, so there will be the CHAT_HTML
and also the CHAT_ENABLE
that have been defined.
The modifications I made are optional, what you really need to do is include one file in the other, using include
.
If you don’t want the include()
(or similar) only use then:
define("Chat_Enable", false); // -- Ativar/Destivar Chat do Servidor
define("Chat_Scripts", '<embed src="http://www.xatech.com/web_gear/chat/chat.swf" quality= "high" width= "500" height= "300" name= "chat" FlashVars="id=158331371&rl=Brazilian" align="middle" allowscriptaccess= "sameDomain" type= "application/x-shockwave-flash" pluginspage= "http://xat.com/update_flash.shtml" /></embed>'); // -- Script do Chat
if(!Chat_Enable){
echo "<div class=\"info-box\"> O Chat se encontra Desativado</div>";
}else{
echo Chat_Scripts;
}
This will solve the problem because the Chat_Enable
and the Chat_Scripts
are defined, test it out here.
Question: why the use of
@
in front of constants? Codes are in the same file?– Woss
to hide the error , are in separate files, but included
– José Júnior
Since it’s going wrong, wouldn’t it be interesting to see the mistake you’re making? Personal tip: avoid using @as much (even) as an application gets out of control very easy in such cases.
– Woss