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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:48:17+00:00 2026-05-27T04:48:17+00:00

I have this kind of class and i would like to take variable outside(return

  • 0

I have this kind of class and i would like to take variable outside(return i guess) so that i would be able to do stuff with it.

    class MyClass{

        private function MyPrivate(){
            $rows = 'SomeVar';
            echo $rows.' is echoed from inside';
            //return $rows;
            return $this->rows;
        }

        function Foo(){
            $this->MyPrivate();
            //$this->rows;
        }
    //return $rows;
    //return $this->rows;
    }

    $myclass = new MyClass;
    $myclass->Foo();

    //$myclass->rows;

    echo '<br />';

    echo $rows.'is echoed from outside';

Echoing variable inside the private function inside the class works, but echoing variable outside does not. Commented out code is what I tried to use to achieve wanted result. I did not make this class so I do not want to mess with it and change anything in it, because I fear it may mess things up.

this is my out put:

SomeVar is echoed from inside
is echoed from outside

As you can see in the second instance there is no SomeVar(variable) present. I am surprised it’s working though.
I am reading up on documentation and tutorials on the web for the past two days but this needs to be solved soon, that is why I posted. Please help. Thanks.

  • 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-27T04:48:17+00:00Added an answer on May 27, 2026 at 4:48 am

    When you use the return statement, you should assign it to a variable. Also, you should have returned $rows, not $this->rows, since they’re actually different variables:

    class MyClass{
    
        private function MyPrivate(){
            $rows = 'SomeVar';
            echo $rows.' is echoed from inside';
            return $rows;
        }
    
        function Foo(){
            return $this->MyPrivate();
        }
    }
    
    $myclass = new MyClass;
    $rows = $myclass->Foo();
    
    echo '<br />';
    
    echo $rows.'is echoed from outside';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file that contains this kind of paths: C:\bad\foo.c C:\good\foo.c C:\good\bar\foo.c C:\good\bar\[variable
i have a class of this kind Class Car { private $color; public function
Assume I have a function template like this: template<class T> inline void doStuff(T* arr)
I have a scenario where I have a custom mapping class. I would like
So I have this kind of setup class Base { public: Base(); virtual void
I have some debugging functions that I would like to refactor, but seeing as
I have this kind of code in some applications (from microsoft) [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage( Microsoft.Naming,
I have this kind of node in my xml document: <parent ...> <a .../>
I have ask this kind of question before, but it seems my previous question
I know questions of this kind have been asked before, but my situation differs

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.