Jump to content

Archived

This topic is now archived and is closed to further replies.

JustinK101

PHP OOP Question

Recommended Posts

[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!

Share this post


Link to post
Share on other sites
[!--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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
[!--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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.