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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:32:50+00:00 2026-05-25T09:32:50+00:00

I’m in a rut and I’m not sure why I elected for this solution.

  • 0

I’m in a rut and I’m not sure why I elected for this solution. Something to do with building a simple ORM for MongoDB which has got way more complicated than I imagined. That’s not the point though.

Anyway, I’ve got all of the document data stored in a protected $_data variable, and the magic methods __get, __set etc. all map to this array.

What I’m after is to modify overloaded variables using some of the following code:

// Dynamically push using
$model->comments += array('comment' => 'Oh hi there amigo.');

// Alternatively, to push:
array_push($model->comments, array('comment' => 'Oh hi there amigo.'));

// Plus, pop, shift, unshift etc.
array_{verb}($model->comments);

Basically, PHP is being a pain and throwing a notification saying:

 Indirect modification of overloaded property Model_Blogpost::$comments has no effect

I’m not enjoying this one bit. If this logic could go in __set and __get that would remove the need for me to make separate classes for every datatype mongo takes. At least, that’s what my logic is saying now.

Does anyone know if something like this is possible? Or do we need to do our own home grown functions to sort this sort of stuff out (as a last resort)?

Thanks in advance, your confused friend.

Edit:

The PHP version is 5.3.6 and returning by reference as in &__get is a bit tricky — here’s a quick overview of the code:

https://github.com/dynamism/Mundo/blob/develop/classes/mundo/object/core.php

Basically, __get calls get() to reduce code duplication. get() merges the loaded model data ($_data) with changed but unsaved model data ($_changed) to give the most recent data type.

It does this by flattening the original and changed data into a single dimension array dot using notation and merges the two. Mongo is so loose it’s a pain. (FYI: you can use original() and changed() to get only $_data or $_changed respectively).

This means that it’s not quite as simple as returning part of an array by reference. If that is the only way to do it, though, it looks like it will have to be refactored?

  • 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-25T09:32:50+00:00Added an answer on May 25, 2026 at 9:32 am

    You may need to upgrade your PHP. This was fixed in later versions (not sure which). Works for me in 5.2.9.

    If you are using a later version and it still issues notices, you’ll want to ensure that you are defining __get with the signature:

    public function &__get($val)

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

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.