Baffling Problems With Class

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Forgive me if I ask a dumb question, I'm new to classes and object programming with PHP,
and cannot figure out what the problem is with this class.  Maybe I have overlooked
something but just can't see it.  The error message usually means a typo or something
that I missed.

I get this error:

Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in crypt_class.php on line 6

I cannot figure it out.  I took this class from the book Essential PHP Security, and
hand-coded it line for line.  But it is baffling why it errors out.  I did modify
the constructor to have the same name as the class, in the book they use __construct
instead of the class name, but it didn't seem to matter or didn't appear to be the

I have tried to use this on two different machines, same error on each machine.
One machine has 4.3.11 the other 4.4.1, but both produce the same error.

Thanks in advance!!

( I can't post my email my employer will fire me )


class crypt

         private $algorithm ;
         private $mode ;
         private $random_source ;

         public  $crypt_key  ;

         public  $cleartext  ;
         public  $ciphertext ;
         public  $iv ;

         public function crypt( $algorithm = MCRYPT_BLOWFISH, $mode = MCRYPT_MODE_CBC, $random_source = MCRYPT_DEV_URANDOM )
         $this->algorithm     = $algorithm ;
         $this->mode          = $mode ;
         $this->random_source = $random_source ;

         public function generate_iv()
         $this->iv = mcrypt_create_iv(  mcrypt_get_iv_size( $this->algorithm, $this->mode ) , $this->random_source ) ;

         public function encrypt()
         $crypt_key = "mykey" ;
         $this->ciphertext = mcrypt_encrypt( $this->algorithm, $crypt_key, $this->cleartext, $this->mode, $this->iv ) ;

         public function decrypt()
         $crypt_key = "mykey" ;
         $this->cleartext = mcrypt_decrypt( $this->algorithm, $crypt_key, $this->ciphertext, $this->mode, $this->iv ) ;



Re: Baffling Problems With Class

This will work in php 5, but for php 4 change

private $algorithm ;
private $mode ;


var $algorithm ;
var $mode ;

Re: Baffling Problems With Class

Sean wrote:
Quoted text here. Click to load it
That fixed it!!!


You da man!


Site Timeline