Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with PHP5 < 5.4.0 #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

alasjo
Copy link

@alasjo alasjo commented Jul 21, 2015

I noticed when testing PHP AES File Encryption in PHP 5.3.1 that the creation of key failed (because hex2bin wasn't introduced until PHP 5.4.0). In the readme of this project it states compatibility with PHP5 so I set out to fulfill that statement.

I have added a function similar to the bin_* functions in the library that checks if hex2bin exists, otherwise using an alternative approach with pack from the PHP.net comment section.

Moreover, the mb_substr function seems to treat length of NULL as zero. I have added a check for NULL length and replace it with the mb_strlen of the string.

Tested and working in PHP 5.3.1.

@jonathangoncalves
Copy link

$len = strlen( **$str** ); for ( $i = 0; $i < $len; $i += 2 ) { $sbin .= pack( "H*", substr( $str, $i, 2 ) ); }

Why'd you use the "$str" variable? Shouldn't be "$string"?

@nbatteur
Copy link

yes Jonathan, it's true. And the good function is:
$len = strlen( $string ); for ( $i = 0; $i < $len; $i += 2 ) { $sbin .= chr( hexdec( $string{$i}.$string{( $i+1 )} ) ); }

Changed from `$str` to `$string`
@alasjo
Copy link
Author

alasjo commented Dec 29, 2016

I missed the typo of $string, commited the correct variable name. Somewhat late...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants