Jump to content

PHP OOP Question


JustinK101

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.