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

StackOverflow

StackOverflow Logo StackOverflow Logo

StackOverflow Navigation

Search
Ask A Question

Mobile menu

Close
Ask A Question
  • Home
  • Add group
  • Feed
  • User Profile
  • Communities
  • Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
Home/ Questions/Q 1217
Next

StackOverflow Latest Questions

Saralyn
  • 0
  • 0
SaralynBegginer
Asked: October 14, 20252025-10-14T12:25:29+00:00 2025-10-14T12:25:29+00:00In: PHP

oop – PHP Design for object oriented database serialization: db initialization and static member functions

  • 0
  • 0
oop – PHP Design for object oriented database serialization: db initialization and static member functions
Closed. This question needs to be more focused. It is not currently accepting answers.


Want to improve this question? Guide the asker to update the question so it focuses on a single, specific problem. Narrowing the question will help others answer the question concisely. You may edit the question if you feel you can improve it yourself. If edited, the question will be reviewed and might be reopened.

This is just a shot in the dark, but I am coding myself down a fiery vortex of doom. I have an ecommerce framework that is “working” and I am trying to improve it and make it easier to manage by converting it to a series of classes that get “serialized” to a MySQL db. SO we have class_order, class_customer, class_product, etc. One of the main things I need to implement is a “transform” method that will read through the existing (very flat and yucky) db schema and reformat everything into this nice new O-O relational schema. As such, I have embedded the table creation into each individual class, along with their corresponding relation table. So eg:

public function create_table() {
        $q = "`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
            `type` SMALLINT NULL,
            `value` decimal(6,2) DEFAULT NULL,
            `usage_count` int null,
          CONSTRAINT code_unique UNIQUE (discount_code)";
        $ret = $this->actually_create_table($q);
        return $ret;
    }

This seems to me to be a great way to document the code within itself.
The problem is that in my “transformer” code, I have to instantiate each class in turn, 1st with empty data to generate the schema with the create_table() method and then just loop through all the records and let the new code do all of its magix. This initial “init with empty data, then call create_table()” setup is cloojy, but “fine”, except when I started to implement checks against the init data. So for example, with customer, if you pass in data with no email, let’s throw an exception bc we don’t want that data in the db. So now I have broken my transformer code, unless I give it “real” data and then just not “store” that. That would probably work, but it cranks the dial on CLoOj is just not very satisfying.
I then started to try to make these methods static so I could avoid instantiation. Well, that leads me to have to staticify lots of other methods and data and eventually I hit a wall with, for just one example, my parent DB class that has all the db related stuff (such as that actually_create_table() method) that all these classes need, including an instantiated $pdo member that obvz cannot be static.
I am now just stuck and wondering if anyone out there has solved a similar design problem bc searching the intarwebs has been fruitless.

0
  • 0 0 Answers
  • 29 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question
  • Popular
  • Answers
  • W3spoint99

    What is Physics? Definition, History, Importance, Scope (Class 11)

    • 1 Answer
  • W3spoint99

    The Living World – Introduction, Classification, Characteristics, FAQs (Class 11 ...

    • 1 Answer
  • W3spoint99

    Explain - Biological Classification (Class 11 - Biology)

    • 1 Answer
  • Saralyn
    Saralyn added an answer When Humans look at their childhood pictures, the first thing… January 17, 2025 at 3:25 pm
  • Saralyn
    Saralyn added an answer Previously, length was measured using units such as the length… January 17, 2025 at 3:25 pm
  • Saralyn
    Saralyn added an answer Measurement forms the fundamental principle to various other branches of… January 17, 2025 at 3:25 pm

Related Questions

  • PhpUnit overwrite server variables from XML

    • 0 Answers
  • Preload Image Warning

    • 0 Answers
  • Error on Laravel, when uploading to hosting and making a ...

    • 0 Answers
  • Cannot get gettext to work in php:fpm-8.2 Docker Container

    • 0 Answers
  • Guzzle not guzzling [closed]

    • 0 Answers

Trending Tags

biology class 11 forces how physics relates to other sciences interdisciplinary science learn mathematics math sets tutorial null sets physics physics and astronomy physics and biology physics and chemistry physics applications science science connections science education sets in mathematics set theory basics types of sets types of sets explained

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

  • About US
  • Privacy Policy
  • Questions
  • Recent Questions
  • Web Stories

© 2025 WikiQuora.Com. All Rights Reserved

Cleantalk Pixel

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.