ionCube Logo
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


 
Post new topic   Reply to topic    ionCube Forum Index -> ionCube PHP Encoder

ioncube_read_file() parameters (and a lesson on booleans)

Author Message
TheWebGuy



Joined: 19 Jun 2005
Posts: 20

PostPosted: Mon Feb 13, 2006 4:08 am    Post subject: ioncube_read_file() parameters (and a lesson on booleans) Reply with quote

Hi all,

Could someone explain how exactly one would determine if an arbitrary file was encoded or not, using the ioncube_read_file() function ?

I've got the routine written to successfully write and read in an include file, but would like to add in an additional check to make sure the file is actually encrypted (the function can read encrypted and plaintext files by default, according to the documentation).

I'd appreciate it if someone could shed light on how to do this.

Thanks,

Will.
Back to top
View user's profile Send private message Visit poster's website
liaison
ionCube Support


Joined: 16 Dec 2004
Posts: 2788

PostPosted: Mon Feb 13, 2006 1:21 pm    Post subject: Reply with quote

Hi

The second by-reference "out parameter" returns this information. Please see section 5.4.1 of the User Guide PDF for the full signature of the read file function.
_________________
Community Admin
Back to top
View user's profile Send private message
TheWebGuy



Joined: 19 Jun 2005
Posts: 20

PostPosted: Mon Feb 13, 2006 10:38 pm    Post subject: Reply with quote

nick wrote:
Hi

The second by-reference "out parameter" returns this information. Please see section 5.4.1 of the User Guide PDF for the full signature of the read file function.


Thanks, Nick.

Sorry, I should have asked a more pointed question.

I have already read the section in the user guide, and was checking the parameter passed back, but wasn't getting the expected result, which is why I posted here.

According to the manual, the &was_encrypted parameter passed back is a boolean, so I was expecting to get a 0 or 1 result.

The result I was actually getting was an empty string or 1, depending on the encryption status, so the check I had in my code wasn't working properly.

Cheers,

Will.
Back to top
View user's profile Send private message Visit poster's website
liaison
ionCube Support


Joined: 16 Dec 2004
Posts: 2788

PostPosted: Tue Feb 14, 2006 12:05 am    Post subject: Reply with quote

Hi

The result is a boolean, and the Loader is correct. Your observations are how PHP behaves with booleans when turned into a string. It is one of the various quirks of PHP.

While on quirks, and one that is simply inexcusable, compare the ?: associativity in PHP with C. The ?: syntax is long established, having its roots in the B language that was developed in 1970 for the PDP-11 and Unix, and derived from one of my personal language favourites, BCPL, developed here in England the year prior. Kept when C was created a couple of years later, and historically now part of the syntax of at least 10 languages, you would expect that PHP would follow the lead of C; but no. The associatvity is the opposite to that of C, and one of the blunders from PHP's creators.

Back to your example of booleans, the point to note is that boolean is an actual type, and not represented by 0 and non-zero, although type conversions may be used to perform comparisons with numerics. If you compare the boolean result with a boolean expression, such as

Code:

if ($was_encoded == true) {
}

or

if ($was_encoded == false) {
}

or just

if ($was_encoded) {
}


then it will work. A boolean false value will also compare correctly against numbers, but not in the following case.

Code:

if ("$x" == "0") {
}


would fail if $x is false, as boolean false converts to the empty string, not "0".

This is similarly shown in the following code that outputs 1, but not 12.

Code:

<?php

$x = false;

if ($x == "0") { // true
  echo "1";
}

if ((string)$x == "0") { // false
  echo "2";
}

?>


To summarise a few tests:

Code:

<?php

$x = false;

var_dump($x == 0); // true

var_dump($x == "0"); // true

var_dump("$x" == 0); // true

var_dump("$x" == "0"); // false

?>


I hope that this helps to clear up the confusion over PHP and booleans.
_________________
Community Admin
Back to top
View user's profile Send private message
TheWebGuy



Joined: 19 Jun 2005
Posts: 20

PostPosted: Tue Feb 14, 2006 12:42 am    Post subject: Reply with quote

Thanks again, Nick.

I modified the code with a couple of extra checks to make sure the result the right type before performing the check, and it's working properly now.

Smile

Will.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    ionCube Forum Index -> ionCube PHP Encoder All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum