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

  • Home
  • SEARCH
  • 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 9218395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:51:16+00:00 2026-06-18T02:51:16+00:00

I am trying to make a class what will contain a set of properties.

  • 0

I am trying to make a class what will contain a set of properties. it will be used like so:

$class = new test_class();

$class->property;
$class->second_property;

Basically, if the properties exist, then they are true, if the properties do not exist, they are false. The properties have no value, only existence.

Now, I want to do something like this:

$class = new test_class();

var_dump($class->property); // false - property does not exist
var_dump($class->second_property); // true - second_property exists

var_dump( (bool) $class); // true

So if even one property of the test class exists, var dumping the $class will show true because it is an object.

However, in the situation where the class has no properties, I want this to happen:

$class = new test_class();

var_dump($class->property); // false - property does not exist
var_dump($class->second_property); // false - second_property does not exist

var_dump( (bool) $class); // false

But, I still want $class to be instanceof the test_class but return false in a logic test.

Is this at all possible? If so, how would I do it?

Thanks, Ozzy

edit:

To clarify, I am already using the __get() magic function. What I want to happen is if the test_class has no properties, then when a var_dump is performed on it, it returns false but an instanceof will return test_class.

elaborating…

I am creating a complex permissions system.
A user gets assigned sections and each section has a set of permissions.

It will work like this:

$user = permissions::get_user(USER_ID_HERE);
// Every property of the $user is a section

var_dump($user->this_section_exists); // true - returns an object
var_dump($user->this_section_doesnt); // false - returns a boolean

If a section exists, then it returns an object of the sections permissions.

var_dump($user->this_section_exists); // true
var_dump($user->this_section_exists->this_permission_exists); // true

var_dump($user->this_section_exists->this_permission_doesnt); // false

Heres the edge case:

var_dump($user->this_section_doesnt); // false

var_dump($user->this_section_doesnt->some_permission);
// This should also return false, which it does,
// But it throws a notice: "Trying to get property of non-object"

I want to be able to either suppress that notice without any modifications to the code which calls the class, ie, no @ to suppress.. or be able to return an object with no properties which evaluates to false on a logic test.

  • 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-18T02:51:17+00:00Added an answer on June 18, 2026 at 2:51 am

    What I want to happen is if the test_class has no properties, then when a var_dump is performed on it, it returns false but an instanceof will return test_class.

    That is not possible, var_dump will always show you the correct type, that’s what it was made for.

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

Sidebar

Related Questions

I'm trying to build a small class-like container that will make it a little
I am trying to make a class that will represent two different behaivours at
I'm trying to make a class where I put a key and value into
I´m trying to make a custom component to javafx, so I make my class
I'm trying to make spreadsheet with class/method modifiers. The spreadsheet itself can be located
I've been trying to make a generic class to represent a range of values
I was trying to make my own class for currencies using longs, but apparently
I am trying to make a standard class library in vs11 with more available
Im trying to make my custom TTreeNode Class for example TCustomTreeNode = class(TTreeNode) private
After trying to make access to a storage class a little easier, I ended

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.