Jul 27, 2008

Globals Inside Functions

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

Globals Inside Functions

kvarnerexpress
I've got the following function, that has a function inside of it, when I run it I get the followin error:

PHP Code:
CODE
Fatal error: Call to a member function on a non-object in



See the code below where I get the error message. I'm guessing the scope of my varaibles is messed up, but I'm not sure how to fix it. I've abbreviated the code so as to make it easier to read.

PHP Code:
CODE
function getMemberRegistrationForm( &$tpl, &$db )
{
   function displayRegistrationForm( $action, &$db, $defaults = NULL, $id = NULL )
   {
       global $registrationForm;
   
       $registrationForm = new HTML_QuickForm('registrationForm');
       $registrationForm->addElement('text', 'lname', 'Last Name:', array('size' => 40, 'maxlength' => 255 ));
   }
   
   if( $registrationForm->validate() ) // <-This is where I get an error
   {
       $registrationForm->freeze();
   }
   else
   {
       displayForm( $registrationForm, $tpl, 'additional_content');
   }
}

getMemberRegistrationForm( $tpl, $db);


Thanks,kvarnerexpress

 

 

 


Reply

dul
*BLEEP*ing hell. What is your registrationForm's source. Does it include that Validate() functuon???

Reply

HmmZ
First of all, sorry if i confuse you, i dont work with such codes (->,=>)

Shouldn't the call to validate() need variables provided to send to ?

Check if you defined all your functions correctly, check the following:
*validate()
*freeze()
*displayForm()

Hope this helps, even a little bit :/


Reply

magiccode9
hi, kvarnerexpress

i dont think that a function can within another function. but following the error displayed, it should be mean you have try to call an method but that method not included in a object ==> the HTML_QuickForm might not be a class. try search if it found HTML_QuickForm class or not.

- hope this help

Reply

arboc7
All I can think of is if validate() is a function that exists (and your other functions also exist) when the getMemberRegistrationForm() function executes...

Sorry I can't help much...but good luck!!

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : globals inside functions

  1. Functions - ??? (7)
  2. Wappy's Php Snippets - I will place here usefull php snippets and functions that i learn/use (13)
    Here is a function you can use to generate a simple random password for whatever use ;-) CODE
    <? function rand_pass($numchar){ $string = str_shuffle
    ("abcdefghijklmnopqrstuvwxyz1234567890"); $password = substr ($string,
    1, $numchar); return ($password); } //example echo
    rand_pass('8'); // will return an 8 character long random password of numbers and
    letters like c8k4ss42 ?> CODE tags added. Here is an extremly usefull search function
    that will search a directory and...
  3. Php Email Validation - A PHP data validation class with many functions (1)
    I've been reading through my old php book (PHP 4.1) and came across this data validation class.
    It can check a number of things ranging from telephone numbers , credit card number formats, email
    address and some others. I checked out some of the methods although I didnt expect it to work 100%
    because I've found source code errors thoughout the book and CD. I tested out a few of the
    methods to check and some of them did return expected results but some didnt either so the data
    validation class was not perfect and it didnt really bother me. The cool thing I found...
  4. Php Functions To Send Mail - (4)
    Which other methods to send mail from a form? I just know mail function, like: mail(string to,
    string subject, string message) Has anyother?...
  5. Arrays Outside A Function - Need to have arrays available to all functions. (3)
    I've got a bunch of arrays that i want to use for more then 1 function. when i declear the
    arrays outside a function i cant use it in a function. This code was originally written in
    javascript by another person but since I plan to use it and extend it with php I had to change it
    from javascript to php code. In the javascript code the arrays were decleared outside the functions
    with 'var arrayname' I read somewhere that declearing javascript variables with
    'var' gives it global access. Any ideas on how I can go about declearing 1 set of these
    arrays t...
  6. Encrypt Functions - (0)
    Here is my 3rd Code: By this code you can encrypt your text: CODE <?php $a =
    md5("hello"); $b = base64_encode("hello"); $c =
    base64_decode("hello"); print "md5 = ".$a." base64_encode =
    ".$b." base64_decode = ".$c; ?> EASY!...
  7. [php](simple) Using Functions To Combine Values In A Form - Really simple example on how to combine values with function (2)
    I just learned this simple method on how to use functions to combine two values from a form. First
    we create ourselves a simple POST form CODE <form method="POST"> Name:
    <input type="text" name="nickname"> Location: <input
    type="text" name="location"> <input type="submit"
    value="Input"> </form> Now we add this php to that same file CODE
    <?php $nick = $_POST['nickname']; $location =
    $_POST['location' ...
  8. Gd Functions - Questions (2)
    Hi all I want begin a new project , my new project is Photo blog ( weblog and image album ) in one
    script for example you can post many image in one post at once case . so its very good and very easy
    but we have some problems . if you can plz help me to fix this problems for example : we need
    change image size for page speed ( we dont want show 16 image in one page ) * we need GD functions
    to change image size to smaller and then show smaller image at page if you know source or tutorial
    about change image size plz post here . thankx we know we can change image size (w...
  9. Some Php Functions Explaination Required - (2)
    Can some one please tell me what is the purpose of the following functions , although there's a
    little explaination with everyline but i cant understand, can some one exaplin it bit clearly and
    tell me that why it is needed in config.inc.php.. what is its purpose and will it work if i dont
    include these files in config.inc.php thanks QUOTE ### Url were Website has been installed, not
    '/' in end! define('C_URL','http://www.test.com/Website'); ### Internal
    path to Website directory define('C_PATH','Z:/home/www.test.com/www/...
  10. Using The Image Editing Functions Of Php - Specifically, lines or regular polygons. (4)
    I've been experimenting a little with PHP's image functions and I was trying to see if I
    could make something that looked 3D, so I started with a cube because it's simple. To make an
    isometric picture of a cube, you need to start with a regular hexagon. However, making a regular
    hexagon isn't the easiest thing. Is there a function to create a regular polygon, or specify an
    angle and magnitude for a vector?...
  11. Writing Your Own Functions In Php - how do i write php functions that takes arguments in php? (2)
    I'll set up the background for the question: I have a separate file that I include on all the
    webpages on my site which I call with PHP using the include() function, so everything will be much
    easier to maintain and update. Well, I have three include files for each page: header.php (includes
    stuff like meta tags, googlebot/spider info), footer.php (the footer/copyright thing), leftnav.php
    (includes the navigation bar). I also like the titles of my pages to be as descriptive as possible
    so I try to include the path of a page (how the user got to that page: "Excite Y...
  12. Confused... - some php functions that i am confused (5)
    First of all, if you have answers to the following QUOTE
    http://www.trap17.com/forums/A-Lot-Of-Php-...ions-t7653.html
    http://www.trap17.com/forums/A-Lot-Of-Html...ions-t7651.html Feel free to answer them all. Now,
    in PHP i know there's microtime, srand, float, array_rand, arrays, foreach, or any other loop
    functions. i'm really confused . Please help me!...
  13. Possible To Put An If Statement Inside A Variable? - (2)
    Ok, so I'm using the include() function on my website. Problem is I'm trying to include a
    search engine form into the layout which is stored in a variable, except the form has an if
    statement in it and I can't seem to get it working. Here's the code I'm trying to
    include... CODE Search: > Just wondering if it is possible for me to put this
    form with the if statement into a variable, or if there's another way that I could go about
    doing this. Thanks....



Looking for globals, inside, functions

Searching Video's for globals, inside, functions
advertisement



Globals Inside Functions



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE