473,322 Members | 1,566 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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 1343
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: TimS | last post by:
I am getting a baffling File not found error (0x800A0035). I am writing asp on a windows 2000 server. I build a path and filename from several fields in a jet database using SQL commands, like...
2
by: Chris Fonnesbeck | last post by:
I thought I knew how to do error handling in python, but apparently I dont. I have a bunch of code to calculate statistical likelihoods, and use error handling to catch invalid parameters. For...
2
by: bfrasca | last post by:
I have a well-formed XML file that I am trying to load into a dataset using the ReadXML method. It keeps telling me that "there are multiple root elements". I can view the data using XML Designer...
12
by: Mike | last post by:
I have posted this before, but no one responds, so here it goes again. I think my question is intimidating people and I have no idea why?!? This is not a new concept. You can do this with other...
4
by: Steve | last post by:
I'm currently running into a problem, and I have no idea what to make of it. I have a class with nested clases and static properties that I'm using to store configuration information using a...
5
by: DarkBlue | last post by:
Following is a code snippet from a pythoncard app the problem is with the sql string called iq1 If either mysubject or mytalktext contains an apostrophe the update fails : Example:...
2
by: noddy | last post by:
In both IE7 and FF2(using firebug) I get the same error. I have a page that displays work contacts' details within a <DIV class = "contactBase" >. The div has a header area <div...
3
by: Scotty | last post by:
I'm a C++ novice and need help figuring out some odd behavior I've encountered. Here's the situation: I create a class and have its constructor store a random number in a private "number"...
1
by: Tim Redfern | last post by:
Hi I'm having an issue that is probably obvious to somebody here but its baffling me.. I'm using python (2.5.1) on an embedded linux sytem system (kernel 2.6.19 I think) with only 32MB memory...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.