0

I am using http://www.openwall.com/phpass/ for hashing. I wish to add namespace to it, and added the single line as shown below.

<?php
namespace myNameSpace;  //I added this one line
class PasswordHash {
  //...
}
?>

I then create my object, however, when I apply the HashPassword method, the results are totally different.

require 'PasswordHash.php';
//$t_hasher = new PasswordHash(8, FALSE); //Original line
$t_hasher = new myNameSpace\PasswordHash(8, FALSE);

$correct = 'test12345';
$hash = $t_hasher->HashPassword($correct);

The only changes were the two lines where I added the namespace to the class and were I initiated the object.

What could cause the differences and how can identify and fix them?

user1032531
  • 24,767
  • 68
  • 217
  • 387
  • please post what your output IS, and what you EXPECT it to be. From your question I can't guess "what the differences are"... since all you provide us with it "the results are totally different"... – Tularis Feb 23 '14 at 13:48
  • @Tularis. I can and will post the differences. Why would there be any differences? What could cause differences based on namespace? – user1032531 Feb 23 '14 at 13:50
  • well, the fact that you suddenly assign your class to a different namespace may lead to problems where a class references a function which used to be iniside _no_ namespace, and is now suddenly in one. This would in turn cause it to function differently. – Tularis Feb 23 '14 at 13:53
  • @Tularis It didn't reference any other functions. I ended up stumbling upon the problem. Something to keep an eye out for. Thank you for your help. – user1032531 Feb 23 '14 at 13:56

1 Answers1

0

Per the documentation http://us2.php.net/__destruct

As of PHP 5.3.3, methods with the same name as the last element of a namespaced class name will no longer be treated as constructor. This change doesn't affect non-namespaced classes.

phpass uses a constructor with the same name as the last element of a namespaced class. Change the name to __construct.

user1032531
  • 24,767
  • 68
  • 217
  • 387