Treehouse: Grow your CSS skills. Land your dream job.

Problem with Classes

  • # November 6, 2011 at 11:58 am

    I’m having a problem with two classes working together

    These are my classes

    class calssOne {

    public function functionOne(){
    $myArray = array(
    array( 'std' => '' , 'type' => 'checkbox' , 'pre' => 'prefix_' , 'name' => 'theName' )

    foreach($myArray as $value){
    $foreachArray = array( $value,$value => $value);

    class classTwo {
    public function functionTow() {

    $get_class = new calssOne();
    $myOptions = $get_class -> functionNameOne();

    if (isset($_POST)) {
    if (isset($_POST)) { //
    foreach loop
    $myOptions = apply_filters('prefix_theName_save_pre', $_POST);

    That code works, but I want to make a foreach loop for the if statement with the comment.

    Everything I try doesn’t work.

    Does anyone have any ideas for this?

    # November 6, 2011 at 12:08 pm

    That code shouldn’t work….or at least it is written incorrectly

    $myOptions never actually equals anything because functionNameOne doesn’t return a value.


    $myOptions = $get_class -> functionNameOne();

    should probably be

    $get_class -> functionNameOne();

    or you should return a value from the functionNameOne, which I’m guessing would be the $foreachArray.

    What do you want the foreach loop to do anyway. And is this for WordPress? Because apply_filters() isn’t a standard PHP function

    # November 6, 2011 at 12:33 pm

    Yes it is for a WordPress plugin, but I’m just trying to learn OOP. It’s based off a this tutorial.

    The exapmle I’m working off of is here. The person who wrote the tutrial doesn’t explain why he used that method, but it does work.

    # November 6, 2011 at 12:55 pm

    Basically I want the foreach to do is loop this.

    if (isset($_POST)) {
    $myOptions = apply_filters('prefix_theName_save_pre', $_POST);

    for each item in $myArray.

    I removed the $myOptions var and it doesn’t.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.