Username:
Password:
Remember me:
Register

Back to forum: Web Programming (HTML, JS, CSS, PHP, MySQL)


Search forums via Google


0 Users appreciate this thread.

Start PHP OOP
 >  >>
Started by Pro64
(2014-07-03 22:16:07)
Pro64 (2014-07-03 22:16:07)
Hello there, PHP Web Developers. I, Pro64, is here to teach and explain what PHP OOP is. This is only for beginners.

PHP OOP (Hypertext Processer Object-Oriented Programming)

LESSON 1
-----------------------

OOP is a style of coding that allows developer to create groups of classes to make their coding more effective and organized.

Your MAY be familiar with



<?php

$text = "Hello World.";
echo $text;

?>



Well in OOP style the coding may look like this


<?php

class data {

public $text = NULL;
public function __construct() {

$this->text = "Hello World";

}

}

$data = new data();
echo $data->text;

?>


Explaination: Looking at the coding, I created a class called "data" which holds the object "text" and set it to NULL. NULL meaning nothing. After that, I created a function __construct() to build data into the object(s). "$this->text = 'Hello World!';", which is only supposed to be used inside the __construct() function, states THIS OBJECT "text" is equal to the string "Hello World!". Now Outside of the class I printed "$data = new data();". data name so it should be like data();. Lets say if the classes name is info. Then you would say "$data = new info();". I took the object text out of the class data by text "echo $data->text". Last view the file content and you should see your results as "Hello World!"

You probably be thinking this in your mind, "Why I can not just do the first way. You don't have to do all of that crazy stuff." Read this article about "Why should I use PHP OOP?" and it will probably persuade you to use it.

Article: http://www.phpclasses.org/blog/post/178-Why-is-it-better-to-develop-in-PHP-with-classes-OOP.html

If I am wrong with any of the information above, It will highly appreciated if you comment where I am incorrect at. I will fix the mistakes I stated.

Lesson 2
-------------------

Coming Soon! (If this is too confusing to the people I will close this topic and not continue with Lesson 2.)

This post has been edited one or more times, the last time was:
2014-07-04 08:06:39




Sarina was here too
angelrulez7 (2014-07-03 23:42:43)
What MarioErmando said.

I don't exactly understand why you would need this. Wellsandlava tried to explain it, but no.

I also don't understand how that works. ye clos dis is tu confuze 4 mi
a
Pro64 (2014-07-04 01:06:14)
Read the god damn article then. I stated that exactly on the thread. :fp: Besides. I used classes to make my on SQL. Thats not simple. People doesn't read the WHOLE THREAD. They just "skim".

This post has been edited one or more times, the last time was:
2014-07-04 08:41:29




Sarina was here too
SPCOxion (2014-07-04 03:24:03)
^
angelrulez7 (2014-07-04 13:51:15)
I read both the thread and the article. I still don't see a valid use.
a
Pro64 (2014-07-04 14:17:38)
Because you are not meant for advanced coding then.

This post has been edited one or more times, the last time was:
2014-07-09 05:30:39




Sarina was here too
angelrulez7 (2014-07-04 22:00:39)
I bet now Pro64 will make a long post about why this is soooooo important now and say we suck at coding.
a
GuitarBoy (2014-07-05 02:22:51)
Advantages:
Data abstraction, encapsulation, modularity, polymorphism, and inheritance.

http://stackoverflow.com/questions/716412/why-use-php-oop-over-basic-functions-and-when

OOP is extremely useful when making libraries, especially if it allows chaining. Chaining is just so awesome with PHP classes.

http://tutorialzine.com/2013/02/24-cool-php-libraries-you-should-know-about/

Just because you guys don't see the purpose in OOP doesn't mean that you're bad coders.

Rather, I would say that you should look into the more advanced stuff. When you really look into software engineering and computer science, you come across a lot of useful things.

This post has been edited one or more times, the last time was:
2014-07-05 09:33:13

http://m.ajango.org - Ajango
New social networking website coming this year! Check for updates frequently!

Ajango Forum Thread
CoolApps (2014-07-05 15:42:25)
I have to agree with the others (Angel, Mega, Mario).
This is kind of useless since you're basically adding more code then you need to and just making it harder for yourself.
I've tried to understand how this logically works but no can do (for some parts).

This post has been edited one or more times, the last time was:
2014-07-05 22:45:02

Newer account: NodePoint
GuitarBoy (2014-07-05 23:50:24)
"In sum, classes allow you to organize better the code you use in your applications by making you put the code that manages related data in the same container, avoiding name collision problems and even promoting reuse of your code eventually of multiple developers in a single project."

Guys. Libraries. APIs.
http://m.ajango.org - Ajango
New social networking website coming this year! Check for updates frequently!

Ajango Forum Thread
CoolApps (2014-07-06 00:46:01)
To be honest, I don't really find that so useful for what I'm doing since the code I'm using works just fine.
Newer account: NodePoint
ryanb000977 (2014-07-06 23:49:31)
The purpose is for better organization. You know SomeLuigi uses OOP a lo too.

This post has been edited one or more times, the last time was:
2014-07-07 06:49:58

GuitarBoy (2014-07-07 03:16:13)
o-o Do polymorphism and inheritance mean NOTHING to you people?

I guess not. >~>
http://m.ajango.org - Ajango
New social networking website coming this year! Check for updates frequently!

Ajango Forum Thread
CoolApps (2014-07-07 14:48:55)
Still, I may not find much use for it, but I could try it out some time.
Newer account: NodePoint
(Capt.)Orb (2014-07-08 22:18:06)
I can see where the others are coming from that this is a bit un-needed but I was able to understand the code well even though I,ve never used it.

This post has been edited one or more times, the last time was:
2014-07-09 05:19:09

Aviation fact: The a380 is the largest commerical aircraft in service!

Go to Splashiverse! Splashiverse
 >  >>

This topic is closed, so you can not post a comment.

This topic's ID: 72064

Back to forum: Web Programming (HTML, JS, CSS, PHP, MySQL)




Total registered users: 8321
New registered users today: 7
Newest registered user: ElegantVulpes

©  Copyright 2026 3DSPlaza. All Rights Reserved