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

  • Home
  • SEARCH
  • 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 7646665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:16:01+00:00 2026-05-31T10:16:01+00:00

When I call a local method from my class as shown in the example

  • 0

When I call a local method from my class as shown in the example below, do I have to put $this-> before it?

Example:

class test{
    public function hello(){
        $this->testing(); // This is what I am using
        testing(); // Does this work?
    }
    private function testing(){
        echo 'hello';
    }
}

The reason why I ask is because I am using the array_map function with a predefined PHP function in it and I am now going to use a function defined by me. This is what I mean:

class test{
    public function hello(){
        array_map('nl2br',$array); // Using predefined PHP function
        array_map('mynl2br',$array); // My custom function defined within this class
    }
    private function mynl2br(){
        echo 'hello';
    }
}
  • 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-31T10:16:02+00:00Added an answer on May 31, 2026 at 10:16 am

    Yes, it is required. testing() refers to the global function by that name, and will cause an error if the function doesn’t exist.

    You can, however, make a “callback” with the $this variable. As you can see from the PHP manual, you need to make an array where the first element is the object and the second element is the method name. So here you could do this:

    array_map(array($this, 'mynl2br'), $array);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I call start() below? package com.example.test; class Bar {} public class Foo<K>
When I call a function, a local scope is erected for that call. Is
Hi I have this code to download images from the server and then to
The method I want to test has a local variable that references an object
I'm really struggling with something here. I have a class module, let's call it
I have a CoreDataUtilities class with a class method that saves a managed object
So I have code like this: <script language=javascript> $(function(){ function hellothere(strng){ showalert(strng); } function
I have a Lua class like below. I am using json to serialize the
When I compile something like this: public class MyClass { void myMethod(String name, String
I have a production server running, and a local development one (this one uses

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.