Jump to content

[SOLVED] php object question


ballhogjoni

Recommended Posts

I have this class and I want to call a function within it when I instansiate the class. My problem is that when I return the value and print it to the screen I get commentcheck Object ( ). I believe I should get something that looks like an array. Any advice/help?

 

<?php
session_start();
class CommentCheck {
function CommentCheck( $post ){
	$sErrorMessage = CommentCheck::captchaCheck( $post );
	print_r($sErrorMessage); //this actually prints correctly on screen
	return $sErrorMessage; //it seems that the error message is not being returned
}
function captchaCheck( $post ){
	include("/home/xxxxxxxxxxxxx/common_scripts/comments_script/comments/includes/comments-config.php");
	include("/home/xxxxxxxxxxxxxxxx/common_scripts/comments_script/comments/includes/clean_input.php");
	$secure_match = strtoupper( trim( $post['secure_match'] ) );
	if ( $secure_match != $_SESSION['captcha'] ){
		$image = FACS_href."articles/images/responses/bad-captcha.gif";
		$size = @getimagesize($image);
		$sErrorMessage = '<img class=\'right\' align="absmiddle" src="'.$image.'" '.$size[3].' />Your security entry does not match the security image. Please take a closer look and try again.';
		return $sErrorMessage;
	}
}
}
?>

 

code that should print the error message:

$oCommentCheck = new CommentCheck($_POST);
	print_r($oCommentCheck);//this prints commentcheck Object ( )

Link to comment
Share on other sites

Yes, you're not creating an object. You need to do this:

 

<?php
$CommentCheck = new CommentCheck();
$oCommentCheck = $CommentCheck->CommentCheck($_POST);
	print_r($oCommentCheck);//this prints commentcheck Object ( )
?>

 

Plus, I don't think you can use the same name for a function that you are already using for your class name.

Link to comment
Share on other sites

Constructors are not suppose to return values, I usually just create a get function:

<?php
function getErrorMessage()
{
return $this->sErrorMessage;
}
?>

<?php
$CommentCheck = new CommentCheck();
	print_r($CommentCheck->getErrorMessage());//this prints the error array
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.