smti Posted July 20, 2010 Share Posted July 20, 2010 Hi Folks, I am writing an PHP application that utilizes OOP. At the moment I have run in to a very simple problem I cannot seem to solve. Here is my situation: I have two independent files -- one file called migration_logic.php and another named queue_intel.php Inside the migration logic is a function which relies on a method inside the queue_intel file. It appears that the function inside the migration_logic file is unable to call the method inside the queue_intel.php file and I am not sure why. Here is my code: Migration_logic.php Function Add_To_Queue(){ Echo "Inside migration logic add to queue function!"; Include("../../../common/queue_intel.php"); $assign = new Queue_intel; $assign->assign_to_queue(); } Queue_Intel.php Class Queue_intel{ function assign_to_queue(){ /** Step 1: Determine from which location the student filed their request. Note: Queue assignment ONLY occurs if the student filed from within an RCHD office location, otherwise queue assignment occurs at ticket conversion time! */ $student_submission_location = $_SESSION['student_submission_location']; if($student_submission_location==0){ //This student is filing from outside and RCHD office! $_SESSION['queueposition'] = 0; } if($student_submission_location==1){ //This student is filing from inside and RCHD location so we need to add them to the proper queue! /** Steps for queue assignment inside an RCHD location: 1. Determine the RCHD location the student is currently visiting by capturing the answer to their question. 2. Count the number of tickets currently active for the desk the student is currently visiting! 3. Assign the student to the queue for the particular RCHD location they are visting */ $rchd_location = $_SESSION['rchd_location']; // <-- This grabs the current location of the student. /** Now we need to count the number of tickets currently in the queue add the new ticket to the bottom of the queue */ Include('../includes/connection.inc.php'); $num_tickets_in_queue = pg_query($dbh, "select * from v2_office_tickets where ticket_status='In Queue' and desk_location = '$rchd_location'"); $num_tickets_in_queue = pg_num_rows($num_tickets_in_queue); //Augment the current queue value and then assign it to variable to put in to the DB. $initial_queue_position=$num_tickets_in_queue+1; //Setup a session variable to pass the queue position to the ticket confirmation form. $_SESSION['queueposition'] = $initial_queue_position; } // End Assign Queue Function } } // End Class Function In short, the function add_to_queue inside the migration_logic.php file needs to be able to be able to call the method assign_to_queue located in the queue_intel.php file. Any help would be greatly appreciated! -Smti Quote Link to comment https://forums.phpfreaks.com/topic/208356-php-oop-question/ Share on other sites More sharing options...
AbraCadaver Posted July 20, 2010 Share Posted July 20, 2010 And why can't it? You haven't given any errors etc... Probably because the Queue_Intel.php hasn't been successfully included. Add this at the top of Migration_logic.php: error_reporting(E_ALL); ini_set('display_errors', '1'); Quote Link to comment https://forums.phpfreaks.com/topic/208356-php-oop-question/#findComment-1088868 Share on other sites More sharing options...
trq Posted July 20, 2010 Share Posted July 20, 2010 Use require instead of include. The file is likely not being found. Having include calls scattered all through your code like that is also a really bad design choice. if you need to move anything you need to change your code accordingly, this is never a good idea. Quote Link to comment https://forums.phpfreaks.com/topic/208356-php-oop-question/#findComment-1088870 Share on other sites More sharing options...
smti Posted July 21, 2010 Author Share Posted July 21, 2010 Hello - After reviewing the advice provided, I have added the error reporting code to the top of both my migration_logic and queue_intel files; I receive one notice, but no errors. I have also changed the include statement to a require and everything appears to work -- the file is being found because the require statement is not outputting an error. FYI: The notice I receive is: Notice: Undefined index: liability in /var/www/rescomp/newresticket/pages/studentfrontend/scripts/migration_logic.php on line 24 This is from a posted variable not related to my problem. Any other thoughts? Thanks, -Smti Quote Link to comment https://forums.phpfreaks.com/topic/208356-php-oop-question/#findComment-1088884 Share on other sites More sharing options...
KevinM1 Posted July 21, 2010 Share Posted July 21, 2010 Are you sure it's a matter of assign_to_queue() not getting invoked and not a matter of your session variables being borked? Quote Link to comment https://forums.phpfreaks.com/topic/208356-php-oop-question/#findComment-1088907 Share on other sites More sharing options...
PFMaBiSmAd Posted July 21, 2010 Share Posted July 21, 2010 I'm going to guess that your code is not even calling the Add_To_Queue() function in the first place. Your code executed as expected when I tried it with a call to the Add_To_Queue() function. When you post a small part of your code out of context it is just about impossible to tell you why your code does not work. Quote Link to comment https://forums.phpfreaks.com/topic/208356-php-oop-question/#findComment-1088908 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.