Jump to content

The ini_set( ) Function


iwato

Recommended Posts

QUESTION: How is it that the ini_set() function can behave, as if it succeeded, but show failure when it is more thoroughly checked?HINT: According to the online PHP manual the ini_set() function is suppose to return the old value upon success, and FALSE upon failure.

<?php	if (ini_get('safe_mode') == 1) {		echo "Safemode is on.<br />";	} else {		echo "Safemode is off.<br />";	}	if (ini_set("safe_mode", 1) == 0) {		echo "Safemode has been reset.<br />";		echo "Its new value is " . ini_get("safe_mode") . ".";	} else {		echo "Safemode was not reset.";	}?>

OUTPUTSafemode is off.Safemode has been reset.Its new value is .Roddy

Link to comment
Share on other sites

I don't think it's about ini_set()... it's about ini_get()... perhaps ini_get() always gets the initial value, not the current value... or that could be only in this case.There's also one other thing... you could be failing, and not see it. You're loosely comparing 0 against 0 (the old value) or false (failure). This condition will be true in either case. You need to do a strict comparrison:

if (ini_set("safe_mode", 1) === 0) {

Link to comment
Share on other sites

I don't think it's about ini_set()... it's about ini_get()... perhaps ini_get() always gets the initial value, not the current value... or that could be only in this case.There's also one other thing... you could be failing, and not see it. You're loosely comparing 0 against 0 (the old value) or false (failure). This condition will be true in either case. You need to do a strict comparison:
if (ini_set("safe_mode", 1) === 0) {

It is true. When I perform a strict comparison, as you suggested the output becomes:Safemode is off.Safemode was not reset.This result corresponds with the failure of the ini_get( ) function to return a value other than the empty set and raises two additional questions:1) Why does the ini_set( ) function not reset the safe_mode property?2) What exactly is being compared when the === operator is applied? Is it the boolean value FALSE or is it the integer 0? Roddy
Link to comment
Share on other sites

2) What exactly is being compared when the === operator is applied? Is it the boolean value FALSE or is it the integer 0?
Type first, and then value. If the type is different, the operator returns false at that point.In loose comparrison (the ==)... I think in case the types are different, the right side argument is casted to the left one's type, but I'm not sure honestly.
Link to comment
Share on other sites

Type first, and then value. If the type is different, the operator returns false at that point.In loose comparrison (the ==)... I think in case the types are different, the right side argument is casted to the left one's type, but I'm not sure honestly.
I'm pretty sure how that goes. In ==, there's typecasting (right gets casted to the left's type), with === it won't and instead will return false upon mismatched types. (pretty much what you just said). :)
Link to comment
Share on other sites

Type first, and then value. If the type is different, the operator returns false at that point.In loose comparrison (the ==)... I think in case the types are different, the right side argument is casted to the left one's type, but I'm not sure honestly.
Together with thescientist you have provided great feedback. Ironically, or perhaps, not so ironically I have just spent the past three days learning how to cast in PHP!Thanks.Roddy
Link to comment
Share on other sites

I'm pretty sure how that goes. In ==, there's typecasting (right gets casted to the left's type), with === it won't and instead will return false upon mismatched types. (pretty much what you just said).
Not really what boen_robot said, but certainly just as informative.This one will be added to my PHP notes.Many thanks!Roddy
Link to comment
Share on other sites

Archived

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

×
×
  • Create New...