Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3481148
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:25:08+00:00 2026-05-18T10:25:08+00:00

Consider this snippet: function f() { return ‘hi’; } echo f(); Vs this snippet:

  • 0

Consider this snippet:

function f() {
    return 'hi';
}

echo f();

Vs this snippet:

echo f();

function f() {
    return 'hi';
}

When I run the scripts, they both produce the same results. That’s great.

But my question is (and I could not find a good answer or reference in any of my searches), is it okay to call the function before it is defined (ie, from a sequential parsing of the script file perspective)?

I don’t want to run into any issues or deprecation down the road if I leave the function call ahead of the function definition block in my script file.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T10:25:09+00:00Added an answer on May 18, 2026 at 10:25 am

    From the Manual:

    Functions need not be defined before
    they are referenced, except when a
    function is conditionally defined as
    shown in the two examples below.

    The possibility to call (reference) a function before it is defined is a PHP intentional feature and I don’t think you need to worry about it becoming deprecated.

    As an observation, if you can choose from declaring the function before or after, it would be common sense to declare it before it’s used.

    Note: The following code will give a fatal error because the function will only be defined at run rime.

    <?php
    echo helloWorld();
    if(1){
        function helloWorld() {
            return 'hello world';
        }
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following snippet: $(document).bind('mousemove', function(e) { $('#someDiv').css({left: e.pageX+'px', top: e.pageY+'px'}); }); This should
Consider this template function: template<typename ReturnT> ReturnT foo(const std::function<ReturnT ()>& fun) { return fun();
Consider this code snippet: transaction.executeSql( 'SELECT * FROM pv_master;', [], function(transaction, result) { if(result.rows.length
Consider this small snippet of JavaScript: for(var i in map.maps) { buttons.push($(<button>).html(i).click(function() { alert(i);
Please consider this code snippet: var ul = $(.list_b).find(li).remove().end(); $.each(Sites, function (index, value) {
Consider this code snippet: $('#selectone').change(function(){ var amount; $.get('search.php', {search:'units'}, function(result){ //this will return only
Consider this JavaScript code snippet: Object.prototype.log = function() { // here, you have a
Consider this snippet: globalVar = 25 def myfunc(paramVar): localVar = 30 print Vars: {globalVar},
Consider this snippet of code: public static class MatchCollectionExtensions { public static IEnumerable<T> AsEnumerable<T>(this
Consider this Python snippet: for a in range(10): if a == 7: pass if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.