470,833 Members | 1,939 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,833 developers. It's quick & easy.

Baffling Problems With Class

Hi,

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
problem.

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 )

<?php

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 ) ;
}

}

?>

Jan 5 '06 #1
2 1250
This will work in php 5, but for php 4 change

private $algorithm ;
private $mode ;
etc...

To

var $algorithm ;
var $mode ;
etc...

Jan 5 '06 #2
Sean wrote:
This will work in php 5, but for php 4 change

private $algorithm ;
private $mode ;
etc...

To

var $algorithm ;
var $mode ;
etc...

That fixed it!!!

Thanks!!

You da man!

:-)

Jan 5 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Chris Fonnesbeck | last post: by
2 posts views Thread by bfrasca | last post: by
12 posts views Thread by Mike | last post: by
4 posts views Thread by Steve | last post: by
5 posts views Thread by DarkBlue | last post: by
1 post views Thread by Tim Redfern | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.