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 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
  • 3 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 would like to use this kind of Objects with json: class Message{ int
I have a method that would like to take as parameter an array of
i have a class of this kind Class Car { private $color; public function
I have this kind of setup : Overridden BaseRunserverCommand that adds another option (--token)
I have this chunk of javascript that's kind of hacked around from http://www.developphp.com/view.php?tid=1248 and
This is kind of a specific question that I had not been able to
Assume I have a function template like this: template<class T> inline void doStuff(T* arr)
So I have this kind of setup class Base { public: Base(); virtual void
I have this kind of question. In my form, i got this as a
I have this kind of node in my xml document: <parent ...> <a .../>

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.