PHP-Nuke v8.3.3
     
stackoverflow
PHP-Nuke v8.3.3 (Titanium Edition) / PHP v8.2.25
Sponsor Tron for PHP-Nuke (Titanium Edition)
::: There is so much more here to see, it takes 30 seconds to register an account and we don't even verify with e-mail! Just register we promise you won't be sorry... ::: Login or Register
IPHub is an IP lookup website featuring Proxy/VPN detection. A free API is available, so you can perform fraud checks on online stores, detect malicious players on online games and much more! Look at this! Click here Look at this! to sign up for FREE today at ipHub ::: Country Music: The Soul Circus Cowboys ::: Sponsor: Brandon Maintenance Management, LLC Phone: 813-846-2865 ::: Sponsor: Big Country Radio - The EJ Morning Show :::

Warning: Undefined array key "session_logged_in" in /home/nuketitanium/public_html/includes/auth.php on line 277

Warning: Undefined array key "session_logged_in" in /home/nuketitanium/public_html/includes/auth.php on line 277

Warning: Undefined array key "session_logged_in" in /home/nuketitanium/public_html/includes/auth.php on line 277

Warning: Undefined array key "session_logged_in" in /home/nuketitanium/public_html/includes/auth.php on line 277

Warning: Undefined array key "session_logged_in" in /home/nuketitanium/public_html/includes/auth.php on line 285

Warning: Undefined array key "session_logged_in" in /home/nuketitanium/public_html/includes/auth.php on line 285

Warning: Undefined array key "session_logged_in" in /home/nuketitanium/public_html/includes/auth.php on line 277

Warning: Undefined array key "session_logged_in" in /home/nuketitanium/public_html/includes/auth.php on line 277

Warning: Undefined array key "session_logged_in" in /home/nuketitanium/public_html/includes/auth.php on line 277

Warning: Undefined array key "session_logged_in" in /home/nuketitanium/public_html/includes/auth.php on line 277

Warning: Undefined array key "session_logged_in" in /home/nuketitanium/public_html/includes/auth.php on line 337

Warning: Undefined array key "session_logged_in" in /home/nuketitanium/public_html/modules/Forums/viewtopic.php on line 415

Warning: Undefined array key "session_logged_in" in /home/nuketitanium/public_html/modules/Forums/viewtopic.php on line 545

Warning: Undefined array key "session_logged_in" in /home/nuketitanium/public_html/modules/Forums/viewtopic.php on line 797

 
Recent Topics   Next 6 >>  
Forum Replies Last Post
Important READ THIS BEFORE DOING ANYTHING ELSE@!
Started by ToneLuke
Forum Rules 0 Thu Apr 27, 2023 10:08 pm
by ToneLuke
Oh yes ! Chlitzxer
Started by Chlitzxer
Introduce Yourself 0 Sun Jul 30, 2023 4:18 am
by Chlitzxer
Oh yes ! DiscoClam
Started by DiscoClam
Introduce Yourself 0 Tue May 02, 2023 2:36 am
by DiscoClam
Oh yes ! Anna here
Started by YuckFou
Introduce Yourself 0 Mon May 01, 2023 2:01 am
by YuckFou
Note I'm prometheus
Started by Prometheus
Introduce Yourself 0 Mon May 01, 2023 1:50 am
by Prometheus
Fight HiJacker
Started by HiJacker
Introduce Yourself 1 Sun Apr 30, 2023 11:53 pm
by ToneLuke

Defining Class Properties
Post new topic Reply to topic printer-friendly view List users that have viewed this topic Thank Post   Forum Index PHP-Nuke Titanium - PHP 8.x
View previous topic View next topic
TheGhost Reply with quote
Senior Admin
Developer
VIP Member
Support Team
31337
Joined Aug 23, 2000
Reputation: 1.4
online
Defining Class Properties
by TheGhost Sun Apr 30, 2023 10:44 pm

To add data to a class, properties, or class-specific variables, are used. These work exactly like regular variables, except they're bound to the object and therefore can only be accessed using the object.

To add a property to MyClass, add the following code to your script:

PHP:  [ Select all ]

class MyClass
{
 
 public $prop1 "I'm a class property!";
}
$obj = new MyClass;
var_dump($obj); 

The keyword public determines the visibility of the property. Next, the property is named using standard variable syntax, and a value is assigned (though class properties do not need an initial value).

To read this property and output it to the browser, reference the object from which to read and the property to be read:

Code: [ Select all ]

echo $obj->prop1;

Because multiple instances of a class can exist, if the individual object is not referenced, the script would be unable to determine which object to read from. The use of the arrow operator (->) is an OOP construct that accesses the contained properties and methods of a given object.

Modify the script in test.php to read out the property rather than dumping the whole class by modifying the code as shown:

PHP:  [ Select all ]

class MyClass
{
 
 public $prop1 "I'm a class property!";
}
$obj = new MyClass;
echo 
$obj->prop1// Output the property 

Reloading your browser now outputs the following:

Code: [ Select all ]

I'm a class property!



Sincerely,
TheGhost

Back to top
View user's profile Send TheGhost a private message Visit user's website
Display posts from previous:

Post new topic Reply to topic printer-friendly view List users that have viewed this topic Thank Post   Forum Index PHP-Nuke Titanium - PHP 8.x All times are UTC - 5 Hours

Page 1 of 1


 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Related topics
 Topics   Replies   Author   Views   Last Post 
No new posts Announcement: READ THIS BEFORE DOING ANYTHING ELSE@! 0 ToneLuke 912 Thu Apr 27, 2023 10:08 pm
ToneLuke View latest post
No new posts Sticky: Object-Oriented PHP for Beginners 0 TheGhost 892 Sun Apr 30, 2023 9:45 pm
TheGhost View latest post
No new posts Welcome to PHP Nuke (Titanium Edition) v8.3.3 0 Administrator 1078 Wed Apr 05, 2023 3:33 am
Administrator View latest post