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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:44:54+00:00 2026-05-14T07:44:54+00:00

I want to use magic function __set() and __get() for storing SQL data inside

  • 0

I want to use magic function __set() and __get() for storing SQL data inside a php5 class and I get some strange issue using them inside a function:

Works:

if (!isset($this->sPrimaryKey) || !isset($this->sTable))
 return false;
$id = $this->{$this->sPrimaryKey};
if (empty($id))
 return false;
echo 'yaay!';

Does not work:

if (!isset($this->sPrimaryKey) || !isset($this->sTable))
    return false;
if (empty($this->{$this->sPrimaryKey}))
   return false;
echo 'yaay!';

would this be a php bug?

  • 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-14T07:44:54+00:00Added an answer on May 14, 2026 at 7:44 am

    empty() first* calls the __isset() method and only if it returns true the __get() method. i.e. your class has to implement __isset() as well.

    E.g.

    <?php
    class Foo {
    
      public function __isset($name) {
        echo "Foo:__isset($name) invoked\n";
    
        return 'bar'===$name;
      }
    
      public function __get($name) {
        echo "Foo:__get($name) invoked\n";
        return 'lalala';
      }
    }
    
    $foo = new Foo;
    var_dump(empty($foo->dummy));
    var_dump(empty($foo->bar));
    

    prints

    Foo:__isset(dummy) invoked
    bool(true)
    Foo:__isset(bar) invoked
    Foo:__get(bar) invoked
    bool(false)
    

    * edit: if it can’t “directly” find an accessible property in the object’s property hashtable.

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

Sidebar

Related Questions

i want use some data from a website with web service. i have a
I want use javascript setInterval function to achieve a box rotate animate effect, I
This topic expands on When do/should I use __construct(), __get(), __set(), and __call() in
I use the code below and get this error InvalidDataExcption: The magic number in
I have these three functions inside the same class: public function checkLogin() { if(isset($this->getSessionVal()))
I want to use the magic of subshells and redirection with the python subprocess
I am trying to learn php and want to use a function to protect
I'm trying to use jquery with a simple php code: $('#some').click(function() { <?php require_once('some1.php?name=some'
I want use this 1 for using Bar code or QR code scanner. I
I want use BYTE_ORDER macro in my Xcode project but i can't because i

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.