June 30, 200917 yr I have the following class, but it is not giving me the result that I require, can anyone please help? Code: class display_class{ var $data; var $curr; var $f_header; var $f_footer; var $header; var $footer; function display_class(){ $this->data = array(); $this->curr = 0; $this->f_header = ""; $this->f_footer = ""; $this->header = ""; $this->footer = ""; } function add_header($data, $type){ if ($type == "f_header"){ $this->f_header = $data; }elseif ($type == "f_footer"){ $this->f_footer = $data; }elseif ($type == "header"){ $this->header = $data; }elseif ($type == "footer"){ $this->footer = $data; }else{ if (isset($process_log->curr)){ echo "<br />GOTO PROCESS LOG"; }else{ echo "<br />NO PROCESS LOG FOUND"; $this->final_header = "ERROR: CLASS/DISPLAY_CLASS ADD_HEADER TYPE WAS NOT RECOGNISED (given data was " . $type . "<br /><br />"; } } } } $process_log = new display_class; $process_log->add_header("br", "f_heasder"); $random = new display_class; $random->add_header("br", "f_heasder"); Result: NO PROCESS LOG FOUND NO PROCESS LOG FOUND Why do I get "no process log found", and not "goto process log"? And how can I fix this?
June 30, 200917 yr im still getting to grips with OOP PHP so.... my thoughts are these when looking at this is $process_log = new display_class; $process_log->add_header("br", "f_heasder"); $random = new display_class; $random->add_header("br", "f_heasder"); Are these typos?
June 30, 200917 yr Author not headers.... I am "intentionally" giving it an option that is not on the if list, forcing it to run: if (isset($process_log->curr)){ echo "GOTO PROCESS LOG"; }else{ echo "NO PROCESS LOG FOUND"; $this->final_header = "ERROR: CLASS/DISPLAY_CLASS ADD_HEADER TYPE WAS NOT RECOGNISED (given data was " . $type . "<br /><br />"; } The end result I want is for it to add an entry to the process log, should "$type" be mistyped in future scripts. I want to achieve result of it returning "GOTO PROCESS LOG"
June 30, 200917 yr OK, I see your point. again I maybe wrong - wouldn't if (isset($process_log->curr)) { echo "<br />GOTO PROCESS LOG"; } become: if (isset($this->curr)) { echo "<br />GOTO PROCESS LOG"; }
June 30, 200917 yr Author In the case that the "class instance" is "process_log" then that would be fine. But say I create a different instance... e.g. $process_log = new display_class(); $process_log->add_header("br", "f_header"); $calendar_return = new display_class(); $calendar_return->add_header("random", "wrong_data"); When I open calendar_return class, and try to run add_header(), I want it to check if "$process_log" instance exists, and then if it does, to write data to that DIFFERENT class instance, so that any errors can be returned neatly at the bottom of the page. Are you following?
June 30, 200917 yr Yea i follow, i think thats where i get suck now then lol just to make sure i follow you... for: $process_log = new display_class(); $process_log->add_header("br", "f_header"); $calendar_return = new display_class(); $calendar_return->add_header("random", "wrong_data"); what do you expect to be returned? and for: $process_log = new display_class; $process_log->add_header("br", "f_heasder"); $random = new display_class; $random->add_header("br", "f_heasder"); what do you expect to be returned?
June 30, 200917 yr Author i was expecting 2 x "GOTO PROCESS LOG" - as on the first of those 4 lines - process log is defined.
June 30, 200917 yr Author I have figured this out now... I had to say: $process_log = new display_class(""); $random = new display_class($process_log); ... CLASS "display_class" function display_class($p_log){ $this->data = array(); $this->curr = 0; if ($p_log == ""){ $this->p_l = "plog"; }else{ $this->p_l = $p_log; } $this->firstline = "1"; } The result is that if "$process_log" is inserted into the class (as it is with $random), it writes $process_log to $p_log, making $p_log the class for within the function - and therefore allowing me to write data to it. The reason I sy that p_l = "plog" if $p_log is blank, is because if it is blank, then the class instance in itself should be the process log, and therefore should write to its own data. Therefore I could use the following later on in the class: if ($this->p_l == "plog"){ $this->addData("<br />ERROR: CLASS/DISPLAY_CLASS ADD_HEADER TYPE WAS NOT RECOGNISED (given data was " . $type . ""); }else{ $this->p_l->addData("<br />ERROR: CLASS/DISPLAY_CLASS ADD_HEADER TYPE WAS NOT RECOGNISED (given data was " . $type . ""); } This will either make total sense or no sense to you hahah, but I dont think it is TOO complicated, so I am hoping you will get it. Thanks for the help regardless.
June 30, 200917 yr i kinda do understand what u did to get round to where u wanted. Hmmm im sure PHP can only get easier as i learn more
June 30, 200917 yr Author lol it does. Now that I look back, I can't believe I didn't figure this one out almost immediately, big blonde moment. I have other problems now lmao.
Create an account or sign in to comment