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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:55:20+00:00 2026-05-20T13:55:20+00:00

I am new here but a strange well problem has me banging my head

  • 0

I am new here but a strange well problem has me banging my head at a wall.
I’m also new in PHP, having previous experience in C# and some in C.
However the problem I have is rather basic variable handling, more explicitly assigning to a variable.

Let’s say we have a code as follows:

class PrebaciApp extends Form {

    public $operation;

    public function getOperation(){
        return $this->operation;
    }
    public function setOperation($setOp){
        $this->operation=$setOp;        
    }

    public function __construct() {
        $this->addWidget(new HiddenBox('hidden'));
        $this->addWidget(new TextBox('text1'));     
        $this->addWidget(new Button('btn1', '+', 'onPlus'));
        $this->addWidget(new Button('btn2', '-', 'onMinus'));       
        $this->addWidget(new Button('btn3', '=', 'onEq'));

    }


    public function onPlus() {

        $this->setOperation('+');
               **var_dump($this->operation);**

    }

    public function onMinus() {

        $this->setOperation('-');

    }

    protected function onEqual() {

    **var_dump($this->operation);**

        switch ($this->operacija) {
        case '+':
            //some logic
        case '-':
            //some logic
        case '*':
            //some logic

        }

        $this->operation='';

    }

}

?>

Lets assume that the first method called is onPlus or onMinus and then onEqual.
Now for some reason the var_dump in onEqual method is saying null, while the var_dump in onPlus is saying string and ‘+’ which is correct.

So my question is, why is $operation, after the methods onPlus or onMinus are over, is set to null?? Am I missing something obviouss in PHP? In Visual Studio with watching variables I could more easily discern the problem.

Edit: Hmm I don’t really know what do you mean by getting the process with which i tested this class. Since there is no watching variables here in PHP, I would just correct then run the php script. The so called F5 testing :D.

However I do have a notion of the problem, the hierarchy is PrebaciApp extends Form, which extends WidgetContainer which holds the collection (array) of Widget objects.

So that’s to much to post here.

But the methods are actually called after pressing a button on the web page itself, which is I think sent through Form or some other class and then calls PrebaciApp. I think the only logical explanation would be that the starting web page then calls another instance of PrebaciApp which has $operation on null.

Maybe I need singleton or static?

  • 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-20T13:55:21+00:00Added an answer on May 20, 2026 at 1:55 pm

    Maybe it is something in your Form class? I ran this test, and added the output. It is as I expected…

    SOrry, I pasted the wrong version. Here’s the file I used:

    <?php
    class PrebaciApp{
    
        public $operation;
    
        public function setOperation($setOp){
            $this->operation=$setOp;
        }
    
        public function __construct() {
    
        }
    
    
        public function onPlus() {
            $this->setOperation('+');
            var_dump($this->operation);
        }
    
        function onEqual() {
    
         var_dump($this->operation);
    
            switch ($this->operation) {
            }
    
            $this->operation='';
           var_dump($this->operation);
    
        }
    
    }
    
    $prebaciApp = new PrebaciApp();
    $prebaciApp->onPlus();
    $prebaciApp->onEqual();
    ?>
    

    and the output:

    string(1) "+"
    string(1) "+"
    string(0) ""
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a strange problem here. I'm moving a (working) site to a new
I'm new to PHP so maybe I am overlooking something here but the following:
fairly new Android developer here. I've come across a strange problem that I'm not
Well I am having a stranger problem here in my android app. I made
Related to my question here but not enough to open a new question. I
I am new to all this, but here goes: There is an apple file
I'm reaaallly new at JSON, but here's what I got. I needed to create
I'm new to IDEA, but very familiar with Eclipse. I followed the instructions here
Here is my code: <%= Html.TextBox(txtId, new { @readonly = readonly })%> But it's
I worked with Haxe and actionscript programming, but I'm new to flex. Here's my

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.