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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:28:22+00:00 2026-05-23T08:28:22+00:00

I’m developing a PHP framework; it started off as application-specific, however it has moved

  • 0

I’m developing a PHP framework; it started off as application-specific, however it has moved into a more agnostic HMVC-style platform which I intend on re-purposing for further projects.

Anyways, while I’m the only developer on the project as it stands, I’m a bit conflicted on my choices of developing the core interfaces.

My main question is (and I understand this could be deemed slightly subjective) is it more appropriate to create a strict interface through which client programmers will work, or permit a bit more flexibility. This is best described through an example:

class MyDataClass{
    public function getData($key){}
    public function setData($key, $value){}
}

This satisfies the requirements (save for implementation details) of a simple data registry. The methods are chain-able by returning $this, and can contain necessary validation logic. Now the alternative PHP approach:

class MyDataClass{
    public function __get($key){}
    public function __set($key, $value){}
}

Sure that works too, and provides a clean implementation through the use of PHP’s magic. Now, the approach I’ve seemed to take most often is:

class MyDataClass{
    public function getData($key){}
    public function setData($key, $value){}
    public function __get($key){ return $this->getData($key); }
    public function __set($key){ $this->setData($key); }
}

Is providing multiple entry points as this example shows a poor choice in design? I always figured it would be a good idea, by centralizing any interaction logic to a single method, but permitting different syntactic choices. I’m now reconsidering this, in favor of a much stricter entry point. A less brief example:

class MySuperDataClass implements ArrayAccess{

    // these do the work
    public function getData($key){}
    public function setData($key, $value){}
    public function getChild($name){}
    public function setChild($name, self $child){}

    // these are just sugary synonyms
    public function offsetGet($key){}
    public function offsetSet($key, $value){}
    public function __get($name){}
    public function __set($name, self $child){}

    // ...

}

Thoughts?


I realized after OZ_‘s response that I hadn’t justified my choice, for understanding the intent of my approach.

For instance, direct method calls (getData() for example) would be used in controllers, to bind data to a view.

$view->setData('foo', 'bar')
     ->setData('alpha', 'beta')
     ->setData('hello', 'world');

Whereas magic sugar is used in view generation for readability and brevity.

<p><?php echo $view['foo']; ?></p>
<p><?php echo $view['alpha']; ?></p>
<p><?php echo $view['hello']; ?></p>

This is how I came to such a convention. I still think it’s a nice approach, but as this question alludes, I’m on the fence now in favor of better practices.


Also: Performance is becoming a concern, as I see the application growing, and these calls are being made iteratively, by using the sugar I’m doubling up my call stack. Sure, micro-optimization I know, but I would think bottleneck potential increases, especially when dealing with PHP magic (if I’ve been led to understand correctly, especially __call()) The only way to check is to profile, sure; I’ve always been a premature optimizer, a habit I’d like to break. Breaking poor design habits is important too.


@jgauffin; the View classes implement ArrayAccess, Iterator and Countable for this behavior, as well as making use of __get/__set magic. This is the sugar for the view, whereas the raw methods are called to bind data from the controllers.

<?php if($view->canRender('post')): ?>
<div>
<?php foreach($view->post as $post): ?>
    <p><?php echo $post['text']; ?></p>
    <?php if($post->canRender('comments')): ?>
    <div>
    <?php foreach($post->comments as $comment): ?>
        <p><?php echo $comment['text']; ?>
    <?php endforeach; ?>
    </div>
    <?php endif; ?>
<?php endforeach; ?>
</div>
<?php endif; ?>
  • 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-23T08:28:22+00:00Added an answer on May 23, 2026 at 8:28 am

    Thoughts:

    1. While exists at least 1 way, where you can build class without magic methods – use that way, avoid magic methods if you can.
    2. If you can’t describe class in interface – class was designed wrong.
    3. Registry is bad pattern. If you need registry – something is wrong in your design.

    Good book about patterns and design

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string

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.