Solved

php - Call to a member function on a non-object

Posted on 2013-05-16
5
786 Views
Last Modified: 2013-05-17
hello there,
I am getting this error (Call to a member function on a non-object)

I am able to render the captcha and see it on the webpage.. when I click on submit form it checks with ajax if all fields have text in it.. then if they do then it checks if the captcha was successfully entered or not by calling validate() and that's were I have the issue saying scoreResult() from ayah is non-object..

whats going on here I have tried maybe 100 different things for the past 5 hours with no luck.

require_once("ayah.php");

class field_captcha extends FormField
{
	public function validate($value)
	{
		global $ayah;
		$score = false;

		$score = $this->ayah->scoreResult();
		if ($score){
			$score = true;
		}

		if (!$score) {
			throw new FormFieldValidationException('incorrect_value');
		}

		return false;
	}


	public function render( array $params = null, Form $form = null )
	{
		$ayah = new AYAH();
		$oldCaptcha = '<input type="hidden" name="captcha[value]" value="test123">';
		$NewCaptcha = $ayah->getPublisherHTML();

		return $oldCaptcha."\n\n".$NewCaptcha;
	}
}

Open in new window

0
Comment
Question by:XK8ER
  • 2
  • 2
5 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
Comment Utility
make $ayah a private variable;
get rid of global $ayah;
change $ayah = new AYAH();  to $this->ayah = new AYAH();
require_once("ayah.php");

class field_captcha extends FormField
{
	private $ayah;
	public function validate($value)
	{
		$score = false;

		$score = $this->ayah->scoreResult();
		if ($score){
			$score = true;
		}

		if (!$score) {
			throw new FormFieldValidationException('incorrect_value');
		}

		return false;
	}


	public function render( array $params = null, Form $form = null )
	{
		$this->ayah = new AYAH();
		$oldCaptcha = '<input type="hidden" name="captcha[value]" value="test123">';
		$NewCaptcha = $ayah->getPublisherHTML();

		return $oldCaptcha."\n\n".$NewCaptcha;
	}
}

Open in new window

0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
I don't think I can help with non-working code, but if the question is about CAPTCHA, this article will show you some of the theory and practice.  Executive summary: It is much easier that most people make it!
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_9849-Making-CAPTCHA-Friendlier-with-PHP-Image-Manipulation.html
0
 
LVL 1

Author Comment

by:XK8ER
Comment Utility
thanks hielo for being so helpful.. I get this now.

Fatal error: Call to a member function scoreResult() on a non-object in

this line
>>$score = $this->ayah->scoreResult();
0
 
LVL 82

Expert Comment

by:hielo
Comment Utility
>>$NewCaptcha = $ayah->getPublisherHTML();
Needed to be changed as well:
$NewCaptcha = $this->ayah->getPublisherHTML();
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
You might want to post a new question about this.  The instantiation of the object either failed or was not executed at all.  As a result the ->method() notation caused the fatal error.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now