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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:17:31+00:00 2026-06-16T07:17:31+00:00

Let´s say I have two PHP classes one called gallery and one called image

  • 0

Let´s say I have two PHP classes one called gallery and one called image.

In the class image I want to include the class gallery, and in the class gallery I want to include the class image.

How could this be properly done – or whats the best way to accomplish this?
What I want to be able to do in the end is to use methods of the class gallery in some methods of the class image.

For example: I have a method “delete” in both classes. In the class gallery the method is used to delete a specific gallery – selected by id. But in the class image the method delete also checks if the deleted image was the last one in a gallery – if so this gallery should be deleted by passing the id to the delete method of the class gallery.

How could this be done best? – Or is there a complete different better way of doing something like this?

Thanks for your anwers!

  • 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-06-16T07:17:32+00:00Added an answer on June 16, 2026 at 7:17 am

    Composition .. the image instance has an instance of the gallery that it belongs to (if it can belong to multiple galleries that complicates things).

    class Image {
       private $gallery;
       private $db;
       public function __construct(Gallery $gallery, DB $db) {
          $this->gallery = $gallery;
          $this->db = $db;
       }
    
       public function delete($id) {
          $this->db->deleteImage($id);
          if ($this->gallery->isEmpty()) {
             $this->gallery->delete($this->gallery->getID());
          }
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have data string like this... one=1&two=2&three=3&four=4&two=2 I'm using php foreach to
Let's say i have two functions in functions.php in Wordpress. function1(){ // it takes
Let's say I've two services: get('my_first_service') get('my_second_service') I want to do something like this:
Let's say I have an object with two different one-to-many relations. Much like: Customer
Let’s say I have two folders in my PHP server root directory: x and
Let's say that I have two links. <li><a href=# id=VALUE1 class=charName>Name 1</a></li> <li><a href=#
Okay, so let's say I have a mysql database table with two columns, one
Let's say I have two files file1.php and file2.php . file1.php has the following
Let's say I have some code like this: <html> <head><title>Title</title></head> <body> <?php if (!$someCondition){
I have two tables: users and user_depts. Let's say (for this question) that users

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.