Page 1 of 1

including class function inside a non class function

Posted: Sun May 08, 2005 8:48 am
by shiznatix
i have a function on a page but i need to put in a result from a class function that i define earlier in the script. all works perfectly but when i put the class function thing inside a non class function i get a error. here is my code

Code: Select all

function NewSecondary($edu_id)
{
    ?>
    <table border="0">
    <form action="education_3.php" method="post">
    <input type="hidden" name="edu_ty" value="1">
    <input type="hidden" name="edu_id" value="<? echo $edu_id; ?>">
      <tr>
        <td>
    <? $lang->DoL('SCHOOL_NAME'); ?>
        </td>
        <td>
    <input type="text" name="edit[sec_school_name]" size="">
        </td>
      </tr>
      <tr>
        <td>
    <? $lang->DoL('COUNTRY'); ?>
        </td>
        <td>
    <? MakeDropMenus('country', '0'); ?>
        </td>
      </tr>
      <tr>
        <td>
    <? $lang->DoL('START_YEAR'); ?>
        </td>
        <td>
    <input type="text" name="edit[year_start]" size="">
        </td>
      </tr>
      <tr>
        <td>
    <? $lang->DoL('END_YEAR'); ?>
        </td>
        <td>
    <input type="text" name="edit[year_end]" size="">
        </td>
      </tr>
      <tr>
        <td>
    <? $lang->DoL('ADDITIONAL_INFO'); ?>
        </td>
        <td>
    <textarea name="edit[add_info]"></textarea>
        </td>
      </tr>
      <tr>
        <td colspan="2" style="text-align: right;">
    <input type="submit" name="submit" value="<? $lang->DoL('FORM_SUBMIT'); ?>">
        </td>
    </form>
    </table>
    <?
}
and i get this error:

Fatal error: Call to a member function on a non-object in /home/users/andrew/public_html/cv/edit/education_3.php on line 90

Posted: Sun May 08, 2005 8:55 am
by vigge89
I've never done such thing, but try this:

Code: Select all

<?php $GLOBALS['lang']->DoL('SCHOOL_NAME'); ?>

Posted: Sun May 08, 2005 9:04 am
by shiznatix
that did the trick. many thanks.

Posted: Sun May 08, 2005 9:56 am
by Chris Corbyn
If you want to use ANY variable (or object) that's in the global scope from within a function you must first declare it using global or alternatively call it from the $GLOBALS[] array.

Same for all cases... not just classes ;-)

Posted: Sun May 08, 2005 2:37 pm
by shiznatix
thanks for the tip!