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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:58:09+00:00 2026-05-23T00:58:09+00:00

To begin, I’m working entirely in PHP using the Yii framework, although Yii ultimately

  • 0

To begin, I’m working entirely in PHP using the Yii framework, although Yii ultimately has little to do with this question.

I’ve got a class, and inside of it I have an array called $data. I want to filter out certain elements of the array that don’t match up with the parameters I’m sending to the class (I’ll put some syntax below to give you a better idea). I am therefore using array_filter, and it requires one of its inputs to be a comparison function (ie. one that returns true or false for a specific element. Any that cause a ‘false’ to be returned are removed from the array).

The problem is that because the function entered is entered in quotes, I don’t see a way to have the comparison function within the actual class. But when the function is outside of the class, I can’t call the instance variable that I need. So what I really need is to be able to call the instance variable outside of the class somehow, to send the instance variable to the function as a parameter, or to somehow keep the comparison function within the class.

Any ideas on this? The class I mentioned is a widget in Yii. Below is the call to that widget (not that important). The relevant parameter is ‘params’.

$this->widget('application.widgets.CListViewParam', array(
    'dataProvider'=>$dataProvider,
    'itemView'=>'_view',
    'params'=>array('receiverId'=>Yii::app()->user->userId),
));

There is an instance variable within a class in the widget to save the parameter:

public $params = array();

Then there is a call to array_filter and the comparison function:

$data = array_filter($data, "filterData");

The actual comparison function is not important, but below is the skeleton. Remember that it is outside of the class.

function filterData($item) {
    // unable to access $this->params inside of this function!
}
  • 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-23T00:58:10+00:00Added an answer on May 23, 2026 at 12:58 am

    If it’s outside the class and can’t access $this->params, then why not just put it inside the class:

    class MyClass {
    
        public $params;
    
        public function widget() {
            // ...
            $filtered = array_filter($array, array($this, 'filterData'));
        }
    
        private function filterData($item) {
           // $this->params is now accessible
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I will begin this question by admitting I am very new to MVC. The
To begin with: Using Entity Framework v4.0. ASP.NET MVC 2.0. Visual Studio 2010. I
To begin with, this question is not a dup of this one , but
I am planning to begin working on my first personal project this June: a
To begin with, the application in question is always going to be on the
I'm about to begin working on a collaborative effort with another vendor. The vendor
I need to begin working with milliseconds in .Net 3.0. The data will be
BEGIN dbms_output.put_line('Welcome to PL/SQL'); END; / I have this code in sample.sql file. How
I begin with an otherwise well formed (and well working) grammar for a language.
Before I begin, my reason for not using OAuth is I believe it is

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.