How to question regarding php classes + functions


#1

Hi, I am using this recaptcha script I have found on Github (https://github.com/JoelLisenby/recaptcha) and what I would like to do is create a simple php function that I can call each time but I am unable to achieve this because my mind has gone blank for around 10 mins now so I was wondering if it is actually possible! As shown in the code below its a functon called recaptcha that I can keep calling but then with the class as its got $recaptcha->button() am I right in thinking you cant call it from the function and can you please show me what I’m doing wrong!

<?php

require_once '../vendor/recaptcha/recaptcha.php';
function recaptcha($form_id, $site_key, $secret_key)
{
	$recaptcha = new Recaptcha($form_id, $site_key, $secret_key);
	return $recaptcha;
}

Thanks


#2

I don’t see the real problem, because your code is doing absolutely nothing. You are not calling the method you are talking about and you do not even call the function anywhere.


#3

Don’t worry! This was a nonsense question that I posted really late when I was really tired and should be deleted!


#4

Don’t be too harsh on yourself. Maybe your question should be deleted but you deserve another chance.


#5

haha thanks, after I posted it the next day I realised what an odd question it was seeing as I use the function() for things that I need on hand always but with recaptcha I clearly don’t so I just adapted the class from github to meet my needs and now it works great! Never even needed a function() :slight_smile:

Thanks and sorry again!