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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:24:12+00:00 2026-05-15T23:24:12+00:00

Im thinking of making a custom datatypes / prototypes for a project im working

  • 0

Im thinking of making a custom datatypes / prototypes for a project im working on but im wondering if its such a good idea?

For example

class String
{
    var $Value;
    private $escaped = false;

    function __construct($String)
    {
        $this->Value = $String;
    }

    function escape()
    {
        if($escaped === false)
        {
            $this->Value = Registry::get('Database')->escape($this->Value);
        }
        return $this;
    }

    function trim()
    {
        $this->Value = trim($this->Value);
        return $this;
    }

    function __toString()
    {
        return $this->__toString();
    }
}
$myValue = new String('Hello World')->trim()->escape();
//$myValue is now prepared for DB insert

There will be prototypes for Array, Object, String, Resource etc..

with arrays there will implement Iterator and such

Some benefits i have in mind is specific data types to objects for example

interface Insert
{
    public function Insert(String $Value); //Array / Object / Resource
}

The custom prototypes would be useful for all strings.

But do you think that the amount of resource usage will out way the benefits ?


updated for POC

$String = new String('ValueText');

sprintf('Test %s',$String); //Works

trim($String); //Works

base64_encode($String); //Works

Also for arrays the SPL Library would be perfect.

class Array implements ArrayAccess, Iterator, Countable
{
   public function __construct(){}
   public function offsetSet($offset,$value){}
   public function offsetExists($offset){}
   public function offsetUnset($offset){}
   public function offsetGet($offset){}
   public function rewind(){}
   public function current(){}
   public function key(){}
   public function next(){}
   public function valid(){}
   public function count(){}
}

Another idea would be the extendible entities

class DatabaseVariable extends String
{
    function __construct($string)
    {
        parent::__constrcut($string);
    }

    public function escape()
    {
        //Blah
    }
}

Having a new entity extend a data-type will make it inherit available methods for that data-type.

As discussed about autoboxing, this is the exact system im looking for but as its not passed discussions yet, for my new project (Forum System) witch I started the other day, do you think that I should go ahead and use my idea?, the user will be able to do faster interactions with datatypes, and if there is a function that does not support an object being passed, we can also do

$RawResource = $Resourtce->Raw();

//...

$Resource->Set($RawResource);
  • 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-15T23:24:12+00:00Added an answer on May 15, 2026 at 11:24 pm

    In my opinion, the time you spend writing this code, fixing this code, and cursing the fact that you can’t use hundreds of PHP functions with your classes will outweigh any advantage this code may have.

    Also, the developer who inherits your project will hate you.

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

Sidebar

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.