Jump to content

can't seem to set a var in my class


c_shelswell

Recommended Posts

Hi I'm very new to oop but going to give it a go. I've got a class that validates and submits a form. It's all working great except that on a successful submission i'd like it to return something to say success. I've set my var $processReturn at the top of my class which is called 'siteSession' if i try and get the data on my page by doing a print_r ($siteSession) i get all my other vars but $processReturn seems to stay empty even though i'm setting it by

$this->processReturn = 'success' i can't figure out why.

 

Here's my code:

include ("form_errors.php");
include ("site_database.php");

class siteSession
{
var $lastPage; 
var $currentUrl;
var $processReturn; // << this is what i want to set


    /* Class constructor */
    function siteSession()
    {
	session_start();

	/* Set referrer page */
        if (isset($_SESSION['formUrl']))
        {
            $this->lastPage = $_SESSION['formUrl'];
        }
        else
        {
            $this->lastPage = "/";
        }

        /* Set current url */
        $this->currentUrl = $_SESSION['formUrl'] = $_SERVER['PHP_SELF'];
}
    
    function newsGigsUpload($data, $fileData)
    {
    	global $formValidation, $siteDB;
    	
    	/****** i have my validation in here **********/

//form success
$this->processReturn = 'success'; // << set here but not working???!!
return 0;
    }

 

does this all make any sense? Any help would be great

Thanks

Link to comment
https://forums.phpfreaks.com/topic/117383-cant-seem-to-set-a-var-in-my-class/
Share on other sites

Well, PHP5 has visibility modifiers, so var is deprecated, along with the fact that your functions have no visibility modifiers either.  You should change it use all of the latest OOP features.  Also, I don't see the point of that class. It's all over the place.  You should read up on OOP so you know how to use it correctly.  OOP is one of the most powerful programming tools (other than a cup of coffee probably) when used correctly...but when used incorrectly, it's just a big waste of time.  Learn how to use it.

I'd been hoping that I could use a class for all my form submissions and mysql inputs. Basically a user would submit a form to process.php that would then call the appropriate function from my siteSession class

 

I presume this is not good practice then?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.