JustinK101 Posted May 11, 2006 Share Posted May 11, 2006 [code]<?include("includes/languageClass.php"); $langObject = new language();function parse($langDir) { $langObject->title = getValueFromLabel($langDir, "text.lang", "title"); $langObject->language = getValueFromLabel($langDir, "text.lang", "language"); $langObject->countryName = getValueFromLabel($langDir, "text.lang", "countryName"); $langObject->mainParagraph = getValueFromLabel($langDir, "text.lang", "mainParagraph"); $langObject->imageFlag = getValueFromLabel($langDir, "references.lang", "imageFlag"); $langObject->imageSymbol = getValueFromLabel($langDir, "references.lang", "imageSymbol"); }?> SOME HTML<?php echo "TITLE = " . $langObject->title . "<br>"; echo "LANGUAGE = " . $langObject->language . "<br>"; echo "COUNTRY NAME = " . $langObject->countryName . "<br>"; echo "MAIN PARAGRAPH = " . $langObject->mainParagraph . "<br>"; echo "IMAGE FLAG = " . $langObject->imageFlag . "<br>"; echo "IMAGE SYMBOL = " . $langObject->imageSymbol . "<br>"; ?>[/code]Don't worry about getValueFromLabel() all it does is return a string. Nothng is echoed when I echo any of the $langObject class member vars. Any ideas why?Thanks! Link to comment https://forums.phpfreaks.com/topic/9534-php-oop-question/ Share on other sites More sharing options...
hvle Posted May 11, 2006 Share Posted May 11, 2006 [!--quoteo(post=373230:date=May 11 2006, 07:03 PM:name=JustinK101)--][div class=\'quotetop\']QUOTE(JustinK101 @ May 11 2006, 07:03 PM) [snapback]373230[/snapback][/div][div class=\'quotemain\'][!--quotec--][code]<?include("includes/languageClass.php"); $langObject = new language();function parse($langDir) { $langObject->title = getValueFromLabel($langDir, "text.lang", "title"); $langObject->language = getValueFromLabel($langDir, "text.lang", "language"); $langObject->countryName = getValueFromLabel($langDir, "text.lang", "countryName"); $langObject->mainParagraph = getValueFromLabel($langDir, "text.lang", "mainParagraph"); $langObject->imageFlag = getValueFromLabel($langDir, "references.lang", "imageFlag"); $langObject->imageSymbol = getValueFromLabel($langDir, "references.lang", "imageSymbol"); }?> SOME HTML<?php echo "TITLE = " . $langObject->title . "<br>"; echo "LANGUAGE = " . $langObject->language . "<br>"; echo "COUNTRY NAME = " . $langObject->countryName . "<br>"; echo "MAIN PARAGRAPH = " . $langObject->mainParagraph . "<br>"; echo "IMAGE FLAG = " . $langObject->imageFlag . "<br>"; echo "IMAGE SYMBOL = " . $langObject->imageSymbol . "<br>"; ?>[/code]Don't worry about getValueFromLabel() all it does is return a string. Nothng is echoed when I echo any of the $langObject class member vars. Any ideas why?Thanks![/quote]Your parse function does not have access to $langObject.you need to either global it or pass it into function as a param.to use global:function parse($langDir){ global $langObject;// rest of the code...}i suppose you know to pass it as a param. Link to comment https://forums.phpfreaks.com/topic/9534-php-oop-question/#findComment-35226 Share on other sites More sharing options...
JustinK101 Posted May 12, 2006 Author Share Posted May 12, 2006 HVLE:Thank you much. That seems stupid you have to set it global in the scope of the function itself. I was trying to the make the instance where I create it global but I kept on getting parse errors. I was trying to do:[code]global $languageObject = new language();[/code] Link to comment https://forums.phpfreaks.com/topic/9534-php-oop-question/#findComment-35299 Share on other sites More sharing options...
hvle Posted May 13, 2006 Share Posted May 13, 2006 [!--quoteo(post=373324:date=May 13 2006, 07:29 AM:name=JustinK101)--][div class=\'quotetop\']QUOTE(JustinK101 @ May 13 2006, 07:29 AM) [snapback]373324[/snapback][/div][div class=\'quotemain\'][!--quotec--]HVLE:Thank you much. That seems stupid you have to set it global in the scope of the function itself. I was trying to the make the instance where I create it global but I kept on getting parse errors. I was trying to do:[code]global $languageObject = new language();[/code][/quote]Yeah, I agree. I can't think of any good reason why they did it like that.You'll find a lot more of "stupid" differences while working with PHP syntax. (I.E. passing by reference, private, public in class). PHP is not a good OOP language. Link to comment https://forums.phpfreaks.com/topic/9534-php-oop-question/#findComment-35349 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.