c_shelswell Posted July 30, 2008 Share Posted July 30, 2008 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 More sharing options...
DarkWater Posted July 30, 2008 Share Posted July 30, 2008 What version of PHP do you use? If you use PHP5, don't use the deprecated PHP 4 syntax for OOP. >_> Link to comment https://forums.phpfreaks.com/topic/117383-cant-seem-to-set-a-var-in-my-class/#findComment-603762 Share on other sites More sharing options...
genericnumber1 Posted July 30, 2008 Share Posted July 30, 2008 Trying to avoid a comment on php4... .. .. ... .. .. where are you calling the newsGigsUpload() method? If you're not the value won't be set until you do call it. Link to comment https://forums.phpfreaks.com/topic/117383-cant-seem-to-set-a-var-in-my-class/#findComment-603764 Share on other sites More sharing options...
c_shelswell Posted July 30, 2008 Author Share Posted July 30, 2008 I've got version 5 installed Link to comment https://forums.phpfreaks.com/topic/117383-cant-seem-to-set-a-var-in-my-class/#findComment-603766 Share on other sites More sharing options...
c_shelswell Posted July 30, 2008 Author Share Posted July 30, 2008 sorry just saw your post properly what do you mean "don't use the deprecated PHP 4 syntax for OOP" as i said i'm pretty new to this Link to comment https://forums.phpfreaks.com/topic/117383-cant-seem-to-set-a-var-in-my-class/#findComment-603767 Share on other sites More sharing options...
DarkWater Posted July 30, 2008 Share Posted July 30, 2008 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. Link to comment https://forums.phpfreaks.com/topic/117383-cant-seem-to-set-a-var-in-my-class/#findComment-603769 Share on other sites More sharing options...
c_shelswell Posted July 30, 2008 Author Share Posted July 30, 2008 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? Link to comment https://forums.phpfreaks.com/topic/117383-cant-seem-to-set-a-var-in-my-class/#findComment-603776 Share on other sites More sharing options...
DarkWater Posted July 30, 2008 Share Posted July 30, 2008 Not good practice at all. Does a session class really have the burden of uploading file data? Not at all. It should be delegated to the proper classes. Honestly, read up on OOP. Link to comment https://forums.phpfreaks.com/topic/117383-cant-seem-to-set-a-var-in-my-class/#findComment-603779 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.