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 8463541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:28:58+00:00 2026-06-10T14:28:58+00:00

There are 3 compilation errors in the init.php code: Undefined variable $ind Undefined variable

  • 0

There are 3 compilation errors in the init.php code:

Undefined variable $ind

Undefined variable $popsize

Undefined variable $chrom

How to solve this issue in the proper way?

main.php

include_once 'init.php';

class Individual {
    public $genes = array();
    //...
}

class Population {
    public $ind = array();
    public $ind_ptr;
    public function setIndPtr(Individual $ind) {
        $this->ind_ptr = $ind;
    }   
}

$popsize = 10;
$chrom = 5;
$pop = new Population();
$pop_ptr = new Population();

$pop = init(pop_ptr);

init.php

 function init(Population $pop_ptr) {
      $pop_ptr->setIndPtr($ind[0]);  
      for ($i = 0 ; $i < $popsize ; $i++) { 
        for ($j = 0; $j < $chrom; $j++) {
          $d = rand(0,1);
          if($d >= 0.5) {
             $pop_ptr->ind_ptr->genes[$j] = 1;
          }
          else {
             $pop_ptr->ind_ptr->genes[$j] = 0;
          } 
        }
        $pop_ptr->setIndPtr($ind[$i+1]);
      }
      $pop_ptr->setIndPtr($ind[0]);

      return $pop_ptr;
  }
  • 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-06-10T14:28:59+00:00Added an answer on June 10, 2026 at 2:28 pm

    Its a matter of scope: Variables are not shared over files, unless you make them global!

    (Badly explained) variables such as

    inc.php

    $a=1;
    

    main.php

    include "inc.php";
    print $a
    

    would work

    however

    inc.php

    function func()
    {
     $a=1;
    }
    

    main.php

    include "inc.php";
    func();
    print $a;
    

    a is not available.

    Hope that makes it clearer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there something wrong in this code? I keep getting compilation errors. Basically I
It's a Heap implemented by myself(for algorithm contest).There are some compilation errors that I
When using client-side compilation for less, and if there are errors, Less is not
Is there an environment variable for GCC/G++ to look for .h files during compilation?
Is there any way to show compilation errors in colors on the terminal? I
Are there an option to skip tests with compilation errors? Just ignore them or
In C#, why are there no compilation errors when the same user-defined conversion exists
Why there are no any compilation errors in the second example but there is
how good this python code ? need criticism) there is a error in this
Is there a compilation symbol to detect if it's running on a compact framework

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.