buildakicker Posted June 16, 2011 Share Posted June 16, 2011 For example, how does this statement work: $foo = $foobar->header[0]; I am a bit lost on it... Thanks! Quote Link to comment Share on other sites More sharing options...
gizmola Posted June 16, 2011 Share Posted June 16, 2011 The -> accesses the class member (variable or method) of the same name, that is a part of $foobar. In that example, $foobar has an array variable or string named "header" and that is returning the 0th element. Quote Link to comment Share on other sites More sharing options...
fugix Posted June 16, 2011 Share Posted June 16, 2011 The -> accesses the class member (variable or method) of the same name, that is a part of $foobar. In that example, $foobar has an array variable or string named "header" and that is returning the 0th element. gizmola did a nice ob of explaining, just to simply give it a name, this is one of the two "object operators" along with :: Quote Link to comment Share on other sites More sharing options...
buildakicker Posted June 16, 2011 Author Share Posted June 16, 2011 Thanks for the replies! So if nothing is getting returned at $foo, then there is something wrong elsewhere then since $foo has array spot 1 data correct? I am trying to get data from an XML file. Certain tags that is... for example $foo = $foobar->header[0]; where <header> has info in the xml file. <Header> <Element> <Description>Select one per Survey</Description> </Element> </Header> Quote Link to comment Share on other sites More sharing options...
fugix Posted June 16, 2011 Share Posted June 16, 2011 if foo is not returning any data, either something is wrong with your class declaration or your class-method declaration/coding inside of the method Quote Link to comment Share on other sites More sharing options...
buildakicker Posted June 16, 2011 Author Share Posted June 16, 2011 This thing works fine in PHP4 btw... Quote Link to comment Share on other sites More sharing options...
Ditoway Posted June 16, 2011 Share Posted June 16, 2011 Thanks for the replies! So if nothing is getting returned at $foo, then there is something wrong elsewhere then since $foo has array spot 1 data correct? It'd be easier if you rephrased your question. Gizmola did a great job of explaining it but I'm going to assume you're pretty new and explain it step by step. -> isn't an operator it's basically a "selector," used to select a method(function) or variable from a class. So if you try to do echo $foo->bar[0]; and $foo isn't an Object(class) then it won't work. In order for it to work you need to assign an Object to the $foo variable, for example: <?php // it's great practice to always start a class name with an uppercase letter. class Foo { // public means you can access the variable from within and outside of the class public $bar = array(); // __construct is the method that's ran when the class is initiated(when you set it to a variable basically). public function __construct ( ) { // $this is referencing THIS CLASS so it's saying "look inside me for a variable called bar and assign it Example." $this->bar[] = 'Example'; } } // assign $f to a new instance of the class Foo $f = new Foo(); // echo out the first value of the bar array echo $f->bar[0]; I hope you can understand what I mean, if not look up the things you don't understand in the PHP manual it will really help! Quote Link to comment Share on other sites More sharing options...
gizmola Posted June 16, 2011 Share Posted June 16, 2011 Thanks for the replies! So if nothing is getting returned at $foo, then there is something wrong elsewhere then since $foo has array spot 1 data correct? I am trying to get data from an XML file. Certain tags that is... for example $foo = $foobar->header[0]; where has info in the xml file. Select one per Survey Without code, there's no way to look at your problem. There were some things changed in php5, but it's not possible to comment on whether they might be effecting your code without actually seeing relevant portions. Quote Link to comment Share on other sites More sharing options...
fugix Posted June 16, 2011 Share Posted June 16, 2011 do you actually have an issue with your code? my first impression was that this was an informative question only. If you are having an issue with something related to this subject, please post your code and we will be glad to help you Quote Link to comment Share on other sites More sharing options...
buildakicker Posted June 16, 2011 Author Share Posted June 16, 2011 Yeah, sorry. It's a big chunk of code. I have been trying to get it to work in php5 from a server with 4 on and I am just not sure where this thing is failing. The parser is from: http://www.criticaldevelopment.net/xml/doc.php I switched to the php5 version as an includes, and it still didn't work. So I have been going through the code trying to find what is up... Besides that parser being included, this is the code: // It's probably best to put this file in a non web-accessible folder for security $configFile = '../documents/WEBRIndex.xml'; $fileContents = file_get_contents($configFile); $indexXML = new XMLParser($fileContents); //Work the magic... $indexXML->Parse(); // ------------------------------------------------------------------ // Associate the users requested view with a document view mapping $docType = $_GET["doc"]; $action = $_GET["act"]; if(check_not_empty($docType) == FALSE) { echo "No document type specified"; exit; } // Find the XML mapping that corresponds with this type.. the ->document->document reference is because // there is an embedded ->document attached automatically by the XML Parser... the second ->document // reference is part of our document $viewXMLFile = null; $viewMapping = null; foreach($indexXML->document->document as $doc) { if(strcmp($doc->documentkey[0]->tagData, $docType) == 0) { $viewMapping = $doc; $viewXMLFile = $doc->viewxml[0]->tagData; break; } } // Make sure we found our XML view mapping if($viewMapping == null) { echo "No mapping found"; exit; } // Now load the actual view XML file into memory //this file contains the <header><body> etc... $viewFile = '../documents/'.$viewXMLFile; $fileContents = file_get_contents($viewFile); $viewXML = new XMLParser($fileContents); //Work the magic... $viewXML->Parse(); // Find the XML mapping that corresponds with this type (because there can be multiple definitions per view XML file) // so we need to do this a second time, (the first was for the index file) $viewMapping = null; foreach($viewXML->document->documentview as $view) { if(strcmp($view->documentkey[0]->tagData, $docType) == 0) { $viewMapping = $view; break; } } // Make sure we found our XML view mapping if($viewMapping == null) { echo "No mapping found"; exit; } function check_not_empty($s, $include_whitespace = false) { if ($include_whitespace) { // make it so strings containing white space are treated as empty too $s = trim($s); } return (isset($s) && strlen($s)); // var is set and not an empty string '' } // --------------------------------------------------------------- // Extract the header and group data from the view template $includeScripts = $viewMapping->includescript; $customScript = $viewMapping->customscript; $headerBlock = $viewMapping->header[0]; $bodyBlock = $viewMapping->body[0]; $documentType = $viewMapping->documenttype[0]->tagData; if(check_not_empty($headerBlock) == FALSE || check_not_empty($bodyBlock) == FALSE || check_not_empty($documentType) == FALSE) { echo " Malformed document view - ".check_not_empty($headerBlock)." - ".check_not_empty($bodyBlock)." - ".check_not_empty($documentType); exit; } Thanks for a look if you have some time ! Quote Link to comment Share on other sites More sharing options...
redixx Posted June 16, 2011 Share Posted June 16, 2011 Do you get an error? Or what isn't working properly. Quote Link to comment Share on other sites More sharing options...
buildakicker Posted June 16, 2011 Author Share Posted June 16, 2011 php error log says: Notice: Undefined index: act in /srv/www/htdocs/webr/app/WEBRView.php on line 40 Notice: Undefined property: XMLTag::$includescript in /srv/www/htdocs/webr/app/WEBRView.php on line 96 Notice: Undefined property: XMLTag::$customscript in /srv/www/htdocs/webr/app/WEBRView.php on line 97 Catchable fatal error: Object of class XMLTag could not be converted to string in /srv/www/htdocs/webr/app/WEBRView.php on line 498 Quote Link to comment Share on other sites More sharing options...
redixx Posted June 16, 2011 Share Posted June 16, 2011 Do you mind posting the code on the lines of each of those errors, or identifying which lines they are in the code you posted. Quote Link to comment Share on other sites More sharing options...
buildakicker Posted June 16, 2011 Author Share Posted June 16, 2011 line 40: $action = $_GET["act"]; // as far as I can see it's not doing anything... line 96: $includeScripts = $viewMapping->includescript; line 97: $customScript = $viewMapping->customscript; Quote Link to comment Share on other sites More sharing options...
fugix Posted June 16, 2011 Share Posted June 16, 2011 firstly, where is you "act" index coming from in your $_GET['act'] declaration. The error states that it is not finding anything with a name of "act" Quote Link to comment Share on other sites More sharing options...
buildakicker Posted June 16, 2011 Author Share Posted June 16, 2011 I commented out line 40, 96 and 97 and got only 1 error at 498. Catchable fatal error: Object of class XMLTag could not be converted to string in /srv/www/htdocs/webr/app/WEBRView.php on line 498 Line 498: function check_not_empty($s, $include_whitespace = false) { if ($include_whitespace) { // make it so strings containing white space are treated as empty too $s = trim($s); } return (isset($s) && strlen($s)); // var is set and not an empty string '' } I think this is an issue with the XMLTag Class... in the http://www.criticaldevelopment.net/xml/parser_php5.phps script maybe... Quote Link to comment Share on other sites More sharing options...
buildakicker Posted July 5, 2011 Author Share Posted July 5, 2011 I am going to close this topic and open a new one with less confusion I hope Quote Link to comment 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.