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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:45:10+00:00 2026-06-08T06:45:10+00:00

i recently made a cookie class but unfortunatly it wasn’t really OOP because i

  • 0

i recently made a cookie class but unfortunatly it wasn’t really OOP because i made the class do 2 different things. that is set/get the cookie and also store te cookie. and OOP means every class has its own operation. so i decided to rewrite my class but i am not able to let it work. here is how i tought i should do it.

i made a interface for the CRUD and a Class that implements this interface called CookieStorage. also i made a Cookie class that sets the cookie values etc. but now by creating this two classes it doesn’t work because i get this error: Fatal error: Call to undefined method CookieStorage::getName() in /Applications/MAMP/htdocs/library/lib/CookieStorage.php on line 27

below you can find my code. thanks in advance!

<?php

interface StorageInterface {
    public function set(Cookie $cookie);
    public function get(Cookie $cookie);
    public function update(Cookie $cookie);
    public function delete(Cookie $cookie);
}

class CookieStorage implements StorageInterface {

/**
 * constructor
 */
public function __construct() {

}

/**
 * Create cookie.
 */
public function set(Cookie $cookie) {
    return setcookie(   
        $this->getName(),
        $this->getValue(),
        $this->getTime(), 
        $this->getPath(), 
        $this->getDomain(), 
        $this->getSecure(), true 
    );
}

/**
 * Get cookie.
 */
public function get(Cookie $cookie) {
    return $_COOKIE[$this->getName()];
}

/**
 * Update cookie.
 */
public function update(Cookie $cookie) {
    return $this->update();
}

public function delete(Cookie $cookie) {
    return $this->delete();
}

}

?>
  • 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-08T06:45:11+00:00Added an answer on June 8, 2026 at 6:45 am

    Looks like you want to use $cookie->getName(). $this points to the storage class, yet you want to store the properties of the cookie parameter instead.

    Update:
    Your call as mentioned in the comment is correct. If you pass your Cookie object, then in the set function of you CookieStorage you’ll need to use $cookie, not $this.

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

Sidebar

Related Questions

I recently made a website but I'm having a really big problem with Internet
I recently made a very simple practice program in Python, that takes user input
I recently made this simple navigation where you have a couple links that have
I recently made a c# printer management tool that uses a WCF service which
I have recently made changes in some code that makes a char name field
So I have a website that I recently made changes to, and one of
I recently made a website, and it works fine on all browsers, but on
I've recently made an UserControl , which took quite a long time, because I
I know that NULL isn't necessary in a programming language, and I recently made
I recently made a Google Apps Script that runs onSubmit of a Google form.

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.