SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2010
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Getting variable names of class

    I need to get variable names..
    For example:
    PHP Code:
    <?php 

    class forex{
      public 
    $example;
      public 
    $example2;
      public 
    $example3;
      
      function 
    getNames()
      {
         return 
    variableNames();
      }
    }

    $class = new forex();
    $class->getNames();
    ?>
    I want to get a (like)array like:
    PHP Code:
    array('example','example2','example3'); 
    I wish I tell you.

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2010
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok thank you so much. I have find more useful usage, but I don't know, maybe it have a problem?

    PHP Code:
    <?php
    class Datas {

        public 
    $one;
        public 
    $two;
        public 
    $three;
       
        public function 
    _GetName()
        {
           return 
    $this;
        }
    }

    $data = new Datas();
    print_r($data->_GetName());
    ?>
    Result:
    Datas Object ( [one] => [two] => [three] => )
    It usage is good or have problems?

  4. #4
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    ...Sure you could do that...but if that is all you wanted
    Code:
    $data = new Datas;
    print_r( $data );
    No need for the method.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2010
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth View Post
    ...Sure you could do that...but if that is all you wanted
    Code:
    $data = new Datas;
    print_r( $data );
    No need for the method.
    No, your codes have problem. You need to convert your object to array. It need to be below:
    PHP Code:
    $data = new Datas;
    $array = (array) $data;
    print_r($array); 

  6. #6
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    No, my code does not have a problem.
    My code returns the same thing your code above returns.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  7. #7
    SitePoint Enthusiast
    Join Date
    Jun 2010
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth View Post
    No, my code does not have a problem.
    My code returns the same thing your code above returns.
    print_r can't show object data.

  8. #8
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Sorry, but you are mistaken. Do not try and school me in PHP, I've been working with it professionally for years. print_r can show object data. Read the documentation: http://www.php.net/manual/en/function.print-r.php
    If given a string, integer or float, the value itself will be printed. If given an array, values will be presented in a format that shows keys and elements. Similar notation is used for objects.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  9. #9
    SitePoint Enthusiast
    Join Date
    Jun 2010
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth View Post
    Sorry, but you are mistaken. Do not try and school me in PHP, I've been working with it professionally for years. print_r can show object data. Read the documentation: http://www.php.net/manual/en/function.print-r.php
    Ohh sorry really. I was want to say array_keys can't use object data. Sorry.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •