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

  • Home
  • SEARCH
  • 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 3342304
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:49:22+00:00 2026-05-18T00:49:22+00:00

I am just getting into PHP classes (OK it took me years …… )

  • 0

I am just getting into PHP classes (OK it took me years …… ) but n the past I have alsways relied on “hard multiple php/sql” coding and the odd function. Now I see the “wisdom etc. of classes. but a bit of help please. A lot of my functions would use a common repeat function for extracting function $args.

OK there is func_get_args(), but all my args are a bit like this (assuming a function called testfunction 🙂 :

testfunction('title=this','li=no','abc=yes');   

How is the best way to create a common function that can be used in many other functions that basically does (below) this (but don’t worry about the echo $a[0].’ -‘. $a[1]; line that is just there for me to see what happens.

function args($args){
    $args = func_get_args();
    foreach ($args as $key=>$val) {
        $a = explode('=',$val);
        echo $a[0].' -'. $a[1];
    }
}

In other words say I have 2 – 5 – 20 different functions all with $args of some description (I would know what the args were though) how do you create function args() that can be used inside all the other args therey saving “lines” of code.

Your help/answers much appreciated

  • 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-18T00:49:22+00:00Added an answer on May 18, 2026 at 12:49 am

    The key point of object-oriented programming is that you create classes and methods that match your data model and business logic. You don’t give any clue about it so it’s impossible to suggest a proper design. However, I’ll assume that you just want some generic tips about how to reuse a function that does some string manipulations.

    If the function is to be reused in related pieces of code, you can write a base class with common features and several child classes that inherit from it:

    <?php
    class Base{
        public function args(){
        }
    }
    class Foo extends Base{
    }
    class Far extends Base{
    }
    ?>
    

    Now, any instance of Foo or Bar has a args() method available:

    <?php
    $a = new Foo;
    $a->args();
    $b = new Bar;
    $b->args();   
    ?>
    

    If the function is to be reused in unrelated pieces of code, you can write a class to encapsulate the reusable functionality:

    Now, you can do StringUtils::args() anywhere you need it.

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

Sidebar

Related Questions

I'm just getting into creating some WCF services, but I have a requirement to
I'm just getting into unit testing, and have written some short tests to check
I'm just getting into ASP.NET Been avoiding it for years as I'm a desktop
I have just been getting into low level programming (reading/writing to memory that sort
I'm just getting back into C++ after a couple of years of doing a
Just getting into PHP web development. I've got an HTML form where a user
Getting started in PHP, but even with a Hello world I'm running into problems
I am just getting into ibatis with SqlMap for the first time and I
I'm just getting into the practice of version control (I'd like to use Eclipse
My little brother is just getting into programming, and for his Science Fair project,

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.