Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Tutorials
[TUT] OOP Programming [TUT]
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="AaidenX" data-source="post: 219892" data-attributes="member: 18868"><p>First off, you must be thinking what OOP means,</p><p> </p><p>O - Object</p><p>O - Oriented</p><p>P - PHP</p><p> </p><p>So I think you got a rough idea, what it means.</p><p> </p><p>Let's start with a bit of code!</p><p> </p><p>[PHP]<?php</p><p> </p><p>?>[/PHP]</p><p> </p><p>Those are the opening and closing codes.</p><p> </p><p>[PHP]<?php</p><p> </p><p>class Test //You may use anything instead of test.</p><p>{</p><p>// Methods and properties are entered here for this class!</p><p>}</p><p>?>[/PHP]</p><p> </p><p>That is a basic structure of a class. We'll go ahead dumbing the variables.</p><p> </p><p>[PHP]<?php</p><p>class Test</p><p>{</p><p> </p><p>}</p><p>$obj = new Test;</p><p>var_dump($obj);</p><p>[/PHP]</p><p> </p><p>So if you execute this, you'll get this display.</p><p> </p><p>[PHP]</p><p>object(Test)#1 (0) { } </p><p>[/PHP]</p><p> </p><p>[PHP]</p><p><?php</p><p> </p><p>class Test {</p><p> </p><p>}</p><p>$obj = new Test;</p><p> </p><p>?>[/PHP]</p><p> </p><p>So in that, we remove the line, var_dump($obj); to stop dumping the variable, we'll be using the echo function to do so.</p><p> </p><p>[PHP]</p><p><?php</p><p>class Test {</p><p> public $prop1 = "I can be anything you like!"</p><p>}</p><p>$obj = new Test;</p><p>[/PHP]</p><p> </p><p>So the above codes add that $prop1 variable which is public and now we'll be showing it in OOP method.</p><p> </p><p>[PHP]</p><p><?php</p><p>class Test {</p><p> public $prop1 = "I can be anything you like!"</p><p>}</p><p>$obj = new Test;</p><p>echo $obj->prop1</p><p>[/PHP]</p><p> </p><p>So, if you execute it, your display would be:</p><p>[PHP]</p><p>I can be anything you like!</p><p>[/PHP]</p><p> </p><p>Give me a like/rep if you find this useful! I'll return like/rep as well! <img src="/styles/default/xenforo/smilies/emojione/smile.png" class="smilie" loading="lazy" alt=":)" title="Smile :)" data-shortname=":)" /></p></blockquote><p></p>
[QUOTE="AaidenX, post: 219892, member: 18868"] First off, you must be thinking what OOP means, O - Object O - Oriented P - PHP So I think you got a rough idea, what it means. Let's start with a bit of code! [PHP]<?php ?>[/PHP] Those are the opening and closing codes. [PHP]<?php class Test //You may use anything instead of test. { // Methods and properties are entered here for this class! } ?>[/PHP] That is a basic structure of a class. We'll go ahead dumbing the variables. [PHP]<?php class Test { } $obj = new Test; var_dump($obj); [/PHP] So if you execute this, you'll get this display. [PHP] object(Test)#1 (0) { } [/PHP] [PHP] <?php class Test { } $obj = new Test; ?>[/PHP] So in that, we remove the line, var_dump($obj); to stop dumping the variable, we'll be using the echo function to do so. [PHP] <?php class Test { public $prop1 = "I can be anything you like!" } $obj = new Test; [/PHP] So the above codes add that $prop1 variable which is public and now we'll be showing it in OOP method. [PHP] <?php class Test { public $prop1 = "I can be anything you like!" } $obj = new Test; echo $obj->prop1 [/PHP] So, if you execute it, your display would be: [PHP] I can be anything you like! [/PHP] Give me a like/rep if you find this useful! I'll return like/rep as well! :) [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Tutorials
[TUT] OOP Programming [TUT]
Top