Jump to content

php.ini


Maartin

Recommended Posts

<?php

 

$a = array();

 

// My Error message:

// Notice: Use of undefined constant test - assumed 'test' in K:\www\a.php on line 7

$a[test] = 1;

 

 

echo $a[test];

?>

 

// ------------------------------------------------------------

I got php 5.313

$a[test] = 1;

// I can't add $a[test] in array anymore!

 

Why this stop working and how can I make php add more array elements?

 

 

 

thanks /Martin

 

 

 

PS: This code work on my Webhotel that use same PHP 5.3.13

My question is why dosen't it work in my WAMP Installation?

Link to comment
Share on other sites

No. And you shouldn't, because using quotes is what you should be doing. Array keys are integers or strings, and with

$a[test] = 1;

PHP tries to find a constant "test". Even if it existed that's not what you'd want it to use. Strings have quotes, so if you want a string then use quotes.

Link to comment
Share on other sites

I been $a['name'] the whole day now...

 

I try use

display_errors = On

in php.in

 

I still get:

Notice: Undefined index: a in ...

if($a['test'] == "b") ...; // when !isset($a['test'])  I get the Notice!;

 

Can I remove Notice when php.ini: display_errors = On

Link to comment
Share on other sites

The code you have showed us will not produce the error you have shown us.

 

Fix your code. If you can't, post the problematic code. Turning error reporting off because you have errors is the sign of a poor programmer.

Link to comment
Share on other sites

if($a['test'] == 'b')

if test is unset I get a Notice like this:

Notice: Use of undefined constant test - assumed 'test' in K:\www\a.php on line 7

 

if I turn off

display_errors = Off

in php.in the page run FINE with ignorant bliss of all the notices!

 

I continue change all the [name]  to ['name'] and is thankful for my new wisdom!

 

My wish was to show only ERRORS not all Notices!

Link to comment
Share on other sites

Again, that error will not be produced by that code. You are likely missing the single quotes somewhere.

 

You can set error reporting to a specific level, but you really should find and fix the notices.

Link to comment
Share on other sites

This is the code in the picture:

<?php

// PHP 5.3.13

// $a = array(); // Error

// $a = array('test' => 'q'); // OK no Notice

 

if($a['test'] != 'b') echo "hello";

?>

 

 

 

Thanks for telling me:

"The code you have showed us will not produce the error you have shown us.

 

Fix your code. If you can't, post the problematic code. Turning error reporting off because you have errors is the sign of a poor programmer."

but you wrong thorpe the code generate this Notice even if you like insult me!

post-134560-13482403589751_thumb.png

Link to comment
Share on other sites

This is the code in the picture:

<?php

// PHP 5.3.13

// $a = array(); // Error

// $a = array('test' => 'q'); // OK no Notice

 

if($a['test'] != 'b') echo "hello";

?>

 

 

 

Thanks for telling me:

"The code you have showed us will not produce the error you have shown us.

 

Fix your code. If you can't, post the problematic code. Turning error reporting off because you have errors is the sign of a poor programmer."

but you wrong thorpe the code generate this Notice even if you like insult me!

 

But he's absolutely right. You should fix errors, not just turn off error reporting/logging. Turning off error reporting an ignoring errors is just plain lazy, and will cause you major headaches in the future.

 

And if you notice, the error message is undefined variable: a, not undefined index: a, as you previously said it was. There's a pretty big difference between the two.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.