including class function inside a non class function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

including class function inside a non class function

Post 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
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

I've never done such thing, but try this:

Code: Select all

<?php $GLOBALS['lang']->DoL('SCHOOL_NAME'); ?>
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

that did the trick. many thanks.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 ;-)
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

thanks for the tip!
Post Reply