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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:20:30+00:00 2026-06-07T13:20:30+00:00

Can OOP programming be emulated with just normal functions? Like with using static variables

  • 0

Can OOP programming be emulated with just normal functions? Like with using static variables and anonymous functions: http://php.net/manual/en/functions.anonymous.php

  • 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-06-07T13:20:32+00:00Added an answer on June 7, 2026 at 1:20 pm

    OOP is about having a constructor function which initiates an object, accessible to other functions “statically” using the this keyword.

    So yes, you can do OOP without using language constructs such as “class”, “this”, or __construct.

    Normal OOP:

    class Something{
        public $member_var;
    
        public function __construct(){
            $this->member_var="x";
        }
    
        public function fill($strValue){
            $this->member_var=$strValue;
        }
    }
    $objInstance=new Something();
    
    $objInstance->fill("abc");
    

    OOP using procedural language constructs (I have avoided the Object class to stay away from any OOP stuff, however it would be better to use it for the $self type, maybe to be able to use the -> accessor, or take advantage of automatic pass by reference):

    function Something_constructor(&$self){
        $self=array(
            "member_var"=>"x",
        );
    }
    
    function fill(&$self, $strValue){
        $self["member_var"]=$strValue;
    }
    
    Something_constructor($arrInstance);
    
    fill($arrInstance, "abc");
    

    Using PHP >=5.3 new anonymous function feature, you could add member functions as properties inside the $self array/object, more so because you can invoke directly ($self["fill"]("abcde")). A nicer accesor is possible if using an object data type for $self.

    Depending on how you design your code, this procedural style OOP might be tweaked to work nicely in simple RPC scenarios (however, the constructor will never return a usable $self object/array, so you might as well go full OOP and have the same problem).

    If going the (object)array() route, you can store the fill function in the object as a property, yet you will never have a $this reference (without passing it as param) or prototypal or any other kind of inheritance. You’d better stick with the class keyword in PHP, there’s no reason to go around it.

    If you also need inheritance, this is where it gets ugly: you need to create renamed functions for overriding, “type” conversion functions for the $self array/object, etc.

    It can be done. If you have complex needs (like inheritance) it might get really ugly. If you have really simple needs, not so ugly, maybe even with advantages.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just started with OOP programming in PHP and I have made a cookie
I can't wrap my head around oop just yet, so I'm sticking with procedural
Now I research OOP-part of Scheme. I can define class in Scheme like this:
I am trying to learn PHP classes so I can begin coding more OOP
Can I authenticate with just Google account username and password instead of using OAuth?
I am building some material for OOP (object oriented programming) in VBA. Can anybody
We are using OOP perl as a programming languge to design this framework, so
I'm new to OOP using PHP and the idea seems a little pointless in
I love doing programming in PHP. But I dont prefer doing it the OOP
The biggest advantage of the OOP vs procedural programming in PHP to my understanding

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.