|
jammaster82
|
 |
« on: September 08, 2009, 12:19:16 PM » |
|
Im setup like this: <?php //somepluginfile.php with the proper header.. blah blah
add_action('admin_menu','my_plugin_menu');
function my_plugin_menu(){ add_options_page('title','name', 8, 'uniqueid', my_plugin_options); }
function my_plugin_options() { echo '<div class="wrap">'; echo '<p>Here is where the form would go if I actually had options.</p>'; echo '<br><hr><br>'; include 'myscriptwithobject.php'; // ^^^^^^^^ does this mess with me? echo '</div>';
}
?>
This is a wordpress admin panel function page. The file im including has an object in it and just creates the object, calls a function and writes some files... if i call this file directly (myscriptwithobject.php) it works from a straight up apache / php interpreter call but buried inside of the wp-schema would this mess with me in scope kind of way?
|
|
|
|
|
Logged
|
The watched pot, never boils... But if you walk away from it , the soup burns. What gives?
|
|
|
|
perkiset
|
 |
« Reply #1 on: September 08, 2009, 12:24:30 PM » |
|
depends on the script. did you try it and it didn't work? there's no immediate or defined reason why it wouldn't, but of course it COULD.
|
|
|
|
|
Logged
|
It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
|
|
|
|
jammaster82
|
 |
« Reply #2 on: September 08, 2009, 12:38:33 PM » |
|
Yeah i tried and it didnt work.. i wonder if by the time i get passed as a weird reference to this function through a hole in the oo headache hierarchy scope fourth dimension if im not getting a proper spin message loop or something i dont understand it at all but yes that is the case i tried it and it didnt work.. im gonna try maybe pasting the actual php that im including instead of doing the include?
|
|
|
|
|
Logged
|
The watched pot, never boils... But if you walk away from it , the soup burns. What gives?
|
|
|
|
perkiset
|
 |
« Reply #3 on: September 08, 2009, 01:08:10 PM » |
|
Oh, wait: you said simply to require your script as a relative location. I think the first problem is one of physical location.
Turn the error level on to E_ALL and see what happens... I'll bet it can't find your code.
|
|
|
|
|
Logged
|
It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
|
|
|
|
jammaster82
|
 |
« Reply #4 on: September 08, 2009, 02:10:34 PM » |
|
it finds the code... it runs the code.. it just doesnt work like it does when directly called..
the code isnt that special but it has a class that is instantiated and inside that class there are some calls to functions inside the class in a loop and the loop completes when i call the page directly from apache/php but not when i include it from the wp admin panel plug in page that i described above...
im stumped atm.
|
|
|
|
« Last Edit: September 08, 2009, 02:13:09 PM by jammaster82 »
|
Logged
|
The watched pot, never boils... But if you walk away from it , the soup burns. What gives?
|
|
|
|
perkiset
|
 |
« Reply #5 on: September 08, 2009, 02:12:52 PM » |
|
That's a drag. When you say, "not working when directly called" what do you mean by this? Are there specific functions that are not working? I'd put a whole buncha debug code into it and see what you get.
In that class, create a debug() function that writes to a file in a known directory. file_put_contents has an append flag, that'll do. Then you can see step by step what is going on.
|
|
|
|
|
Logged
|
It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
|
|
|
|
jammaster82
|
 |
« Reply #6 on: September 08, 2009, 02:34:45 PM » |
|
okay ive actually done that and it doesnt gracefully exit a specific function in the class which has code like this: case 'q' : $this->q->add($c, &$this); break; so is &this a pointer to the object being handed to itself? 
|
|
|
|
|
Logged
|
The watched pot, never boils... But if you walk away from it , the soup burns. What gives?
|
|
|
|
perkiset
|
 |
« Reply #7 on: September 08, 2009, 02:36:45 PM » |
|
Why are you passing a reference to the object? First off, you don't need to, you can pass $this and it is the same thing - objects are always passed by reference. But second, if you're calling the q->add function within the context of (this) already via this->q->add, why pass $this at all?
|
|
|
|
|
Logged
|
It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
|
|
|
|
jammaster82
|
 |
« Reply #8 on: September 09, 2009, 08:33:58 PM » |
|
I agree, and my braingina hymen is being rent from bottom to top here on this one... why does it work when directly called but not in the position of the plugin? (whatever position that is..) cause the way i think about it your right... but it works i didnt write the code this is one of those "its almost done can you fix it" somebody elses code things... Im considering just rewriting the thing straight down monolithic style so i can deploy it for now.... I guess this is where i still dont completely understand the oo thing but can hack my way around it for now.... you know wtf is $this anyway and if it is me, how can i hand myself to someone and it work .... will report on my findings, that is if im able to understand this quagmire.... thefactthat (all one word  ) it works called directly tellls me that it IS possible to pass a referenc of myself TO a function of myself .... this is kinda where i got lost in C++ when dealing with linked lists.... its a cool concept but in another dimension from where i learned to code.
|
|
|
|
|
Logged
|
The watched pot, never boils... But if you walk away from it , the soup burns. What gives?
|
|
|
|
vsloathe
|
 |
« Reply #9 on: September 10, 2009, 09:01:41 AM » |
|
Check that your file is not being called:
1) in the constructor of another class 2) in the destructor of another class 3) while output buffering is turned on
any of those could fuck you.
|
|
|
|
|
Logged
|
hai
|
|
|
|
jammaster82
|
 |
« Reply #10 on: September 10, 2009, 09:27:37 AM » |
|
Thanks! it does use output buffering.... Why should it use output buffering as opposed to just building a string... is there some sort of advantage to output buffering as opposed to old fashioned string building?
|
|
|
|
|
Logged
|
The watched pot, never boils... But if you walk away from it , the soup burns. What gives?
|
|
|
|
jammaster82
|
 |
« Reply #11 on: September 13, 2009, 06:31:32 PM » |
|
Yup the output buffer screwed me. Please consider the following code: (i have ommitted a lot of the guts but included enough in this example to discuss a few things about it.) I have a few questions but id like to start with these two: First off, where is the constructor? is the function Parser, named the same as the class considered a constructor? Ill ask my other questions later but just want to get this out there.. additionally are the destructors automatic and not needed? I have some more questions about $this but lets start here. class Parser { var $str;
function Parser($f, $opt = '',$size) { $this->q = new Q(); } function setstate($state, $node) {.\ // setstate code... } // set state function addBlock() { $this->res .= "<QUESTION>" . $this->s . "</QUESTION>"; $this->q = new Q(); } function doparse() { while (($c = $this->get()) !== -1) { switch ($this->state) { case 'q' : $this->q->add($c, &$this); if($x) $this->setstate('q',&$this); break; // ... blah blah } } logit("last line in do parse"); logit($this->res); return $this->res; } // end of function doparse()
} // end of clASS parser
class N { var $t; var $s; var $st; function add($x, $parser) { } } class Q extends N { var $t; var $s; var $st; function add($x, & $parser) {
if ($x == '_'&&$this->t!='b') { $d = $parser->readahead(); if ($d == '_') { $this->t = 'b'; } } return $parser->setstate('c', $this); } } // end class q
|
|
|
|
|
Logged
|
The watched pot, never boils... But if you walk away from it , the soup burns. What gives?
|
|
|
|
perkiset
|
 |
« Reply #12 on: September 13, 2009, 07:01:39 PM » |
|
First off, where is the constructor? is the function Parser, named the same as the class considered a constructor?
Yes. In PHP4 that was the standard. The PHP5 syntax defines the magic functions: __construct, __destruct and a few others that are not pertinent here.
|
|
|
|
|
Logged
|
It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
|
|
|
|
jammaster82
|
 |
« Reply #13 on: September 13, 2009, 07:06:56 PM » |
|
Thanks for your help, as always.
Next, I want to know what is the name of the feature of class N ... is N overloaded.... displaying inheritance?
In the declaration of Q it 'extends N'..
Why even define n it doesnt even save typing cause you have to type all that other stuff as well..
|
|
|
|
|
Logged
|
The watched pot, never boils... But if you walk away from it , the soup burns. What gives?
|
|
|
|
perkiset
|
 |
« Reply #14 on: September 13, 2009, 07:25:24 PM » |
|
In the declaration of Q it 'extends N'..
Why even define n it doesnt even save typing cause you have to type all that other stuff as well..
Well, I can't answer what they were thinking building the class hierarchy that way, but yes: the way you inherit is with extends. Here is some BS code that should give you and idea of what the OO stuff looks like. Pingback if you need more. class base {
protected $myVal;
function __construct($aVal)
{
$this->myVal = $aVal;
} }
class child1 extends base {
function __construct($aVal)
{
parent::__construct($aVal);
$this->myVal *= 2;
} }
class child2 extends child1 {
function __construct()
{
parent::__construct(10);
}
public function getMyVal()
{
return $this->myVal;
} }
$x = new child2(); echo $x->getMyVal();
// would echo "20"
|
|
|
|
|
Logged
|
It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
|
|
|
|