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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:22:04+00:00 2026-06-10T00:22:04+00:00

If I create a constructor function within my class with the variable called $base_url

  • 0

If I create a constructor function within my class with the variable called $base_url = 'mydomain'. How could I access this via other functions as a general variable?

I have tried creating a test function with echo $base_url but it did not return a variable.

  • 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-10T00:22:05+00:00Added an answer on June 10, 2026 at 12:22 am

    Make it a class variable and reference it with $this

    class MyClass {
    
        public $base_url; // change access modifier as needed
    
        public function __construct($base) {
            $this->base_url = $base;
        }
    
        public function getBaseUrl() {
            return $this->base_url;
        }
    
        public function url($url) {
            return $this->base_url . $url;
        }
    
    }
    
    $myClass = new MyClass('http://example.com/');
    echo $myClass->url('register');
    

    Output: http://example.com/register

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

Sidebar

Related Questions

I have a class within Javascript with a variable assigned in the constructor. I
Having some trouble understanding variable scope within a class structure. I want to create
If I create and use some Objective-C classes in an __attribute__((constructor)) function and they
This is about inheritance in JavaScript. Suppose I create a constructor Bird(), and another
Based on constructor of the class. create or destroy new methods. I often requires
I'd like to be able to dynamically create an instance method within a class'
I am attempting to create a constructor for my controller that references a function
how would i create a function that uses templates within itself but not in
I have this class I created on a theme within a Wordpress environment. class
Function constructors are able to create objects in javascript but I have a more

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.