Category Archives: oop

  • 0

what is difference between constant and static in php

Category : oop

what is difference between constant and static in php

 

 

 

 

 

 

 

 

What is difference between constant and static in php

Constants

Besides properties and methods in the body of the class can also be defined constants.
A constant is declared with the const keyword followed by a name (is not prefixed with a dollar sign like properties).
– Syntax:
const CONSTANT_NAME
The main difference between properties and constants is that the constant value cannot be changed once it is set.
Constants are recognized as public, they are not defined with public, private or protected attribute.
Constants are accessed via the class name in conjunction with ::
– Syntax:
Class_Name::CONSTANT_NAME

 

I also assume, since static members (functions and variables) do not get instantiated into a new corresponding object, then constants also do not (since they are accessed with the :: operator).

class ClassName {
static $my_var = 20; /* defaults to public unless otherwise specified */
const MY_CONST = 10;
}
echo ClassName::$my_var; // returns 20
echo ClassName::MY_CONST; // returns 10
ClassName::$my_var = 50; // now equals 50
ClassName::MY_CONST = 100; // error! won’t work.

 class constants are always public but static variables can be private or protected. I use class constants mostly for ‘enumerated’ parameter values.

Public, protected, and private are irrelevant in terms of consts (which are always public); they are only useful for class variables, including static variable.

  • public static variables can be accessed anywhere via ClassName::$variable.
  • protected static variables can be accessed by the defining class or extending classes via ClassName::$variable.
  • private static variables can be accessed only by the defining class via ClassName::$variable.
  • Declaring a class method or property as statis makes them accessible without needing an instantiation of the class.A class constant is just like a normal constant, it cannot be changed at runtime. This is also the only reason you will ever use const for.Private, public and protected are access modifiers that describes who can access which parameter/method.Public means that all other objects gets access. Private means that only the instantiated class gets access. Protected that the instantiated class and derived classes gets access

  • 0

how to show json data using api

Tags :

Category : html , oop

how to show json data using api

 

 

 

 

 

 

 

 

how to show json data using api

<html>

<title></title>

<head>

<script type=”text/javascript” src=”http://code.jquery.com/jquery-latest.js”></script>
<script type=”text/javascript”>// <![CDATA[
      $(“#searchterm”).keyup(function(e){
        var q = $(“#searchterm”).val();
        $.getJSON(“http://en.wikipedia.org/w/api.php?callback=?”,
        {
          search: q,
          action: “query”,
          list: “search”,
          format: “json”
        },
        function(data) {
          $(“#results”).empty();
          $(“#results”).append(“
 
Results for <b>” + q + “</b>
 
“);
          $.each(data.query.search, function(i,item){
            $(“#results”).append(“
<div><a href=’http://en.wikipedia.org/wiki/” + encodeURIComponent(item.title) + “‘>” + item.title + “</a>” + item.snippet + “</div>
“);
          });
        });
      });
 
// ]]></script>
</head>
<body>
<input id=”searchterm” type=”text” /> <button id=”search”>search</button>
</body>
</html>

  • 0

what is inheritance, polymorphism and abstraction in php

Category : oop , php , programming , web application

what is inheritance, polymorphism and abstraction in php

 

 

 

 

 

 

 

 

what is inheritance, polymorphism and abstraction in php

what is inheritance in php, what is polymorphism in php ,what is abstraction in php

 

 

what is inheritance in php
what is polymorphism in php
what is abstraction in php
what is aggregation in php
what is association in php
what is inheritance in php
these all concepts come from oop object oriented programming where we can have multiple shapes or forms
using same object and the same object we can take some or more  or extend this object to own accord.
let’s suppose i make a object now if i am in  procedural programming that would demand a long and lengthy procedure and that cannot be handled dynamically.
now come to the topic i make an object using oop and i want to instatiate it in different forms keeping it view the concept of giving it more features leaving same object at same prosition.
that’s way i can have many forms of same object using inheritance feature.
for this we use extends keyword in php

what is polymorphism in php
polymorphism means different forms of the same object where the same object plays different roles
like person account would be in different forms , it can be used in statements for credit, debits etc. this is personal form of use
person account can be used in fiscal policy, account maintenance policies
person account can be used in category shape for upper or lower view.
now it does not mean that they would be now viewed separately rather person account would be set up that way it would be viewed in many purposes using same entity.

what is abstraction in php
as abstraction term deals with some idea or plan or concept which can be felt but never can be touched.
in programming , it means that when we develop some entities or something that can be utilized
in many shapes but it can be viewed outside of any scope. and we do not what is happening in it.
we can just use them the big example of it api(application programming interface) where we use
or programme everything but we are unable to view or see the inner logic of api.
at this point someone can say that we can get this type of keyword friend or private keywords.
that is the good idea but they are more close terms to classes but abstraction is a big term where classes are hidden from outside (here outside does not mean that outside world )
here it means that from objects or classes that are using theme. even class or classes do not know how it is being abstracted but classes know what is being abstracted as per this shoud compulsory so that abstraction can be utilized in best form for accomplishing little or big tasks of programming
in short, i cannot say that it is complete here , it would require big time and lot of papers to spend and to read for fully awareness of what is abstraction.

what is aggregation in php
aggregation is a term where different entities make a whole entity but every entity has its own value
and if separeted form others it has upon itself no effect of others ; it can sustain without others.
example as class room consists of boys or girls or boths , table,chair and blackboard etc.
if we exclude girls or chairs etc. from class , class would  remain class , girls would remain girls ; in short, they are their own integrity  that is called aggregation.

what is association
association is a term where unit entity if consists of many parts , and if any part is excluded from it , it would not remain a unit entity
as example of chair it has four legs , one seat and one back now if we remove one leg or a seat
chair  would not a complete entity ; it has lost its shape that is called association .
now we can conclude that association is a name of joining things together if one thing is removed and whole if cannot sustain its shape , that is called association.


  • 0

what is difference between object and function

Category : oop

oop

 

 

 

 

 

 

 

 

 

 

 

 

There is a great difference between these two but they are mostly correlated to each other and function are normally dependent on object  as the term of function applies where you can set parameters and attributes to some object and they would reside in the specified object and outside of object and can be declared public or private or protected that depends !.

And we can call them anywhere in our programme as per its access but when you go to object object always has a place in a class and it is normally has a function or more as per definition says that if an object exists in a class what kind of role it is performing there minor or major that depends on the situation  and object relationship with function we cannot deny it as per in a class some objects has more value than other and some has less value than itself . what role that object is supposed to be performing that depends on the situation . There we can also extract two more terms as function oriented programming and object oriented  programming when they are two ; two ignite the programming the idea of oop(object oriented progamming ) really helped us a lot for adapting a fast and robust way to programming and we cannot achieve oop way unless we are there in function oriented programming that ‘s nice idea we are adopting today .

In short, we can adapt many methodologies for programming as function oriented way or object oriented way function oriented way is now evolving itself and becoming a part of object oriented  programming.


  • 0

what are magic methods in php and why we use them

Category : oop , php

what are magic methods in php and why we use them

 

 

 

 

 

 

what are magic methods in php and why we use them

Magic methods in php have their importance and they are really important and they are start with double underscore(__).

 

 

 

they are listed below:

  1. __autoload()
  2. __clone()
  3. __constuctor()
  4. __call()
  5. __destruct()
  6. __get()
  7. __isset()
  8. __set()
  9. __sleep()
  10. __tostring()
  11. __unset()
  12. __wakeup()

they are built in php functions and we can use them anywhere in class,method , function or anywhere else.

now question comes to our mind why we use them the answer is simple as that we do not need to go hard coding for them ; actuall

they are made for development ease as __isset(),__set(),__unset() and __get() are used for restoring ,determining and inspecting the elements in class or database etc.

And more about __sleep() is used to return to us the array  of all variables that need to be saved and while __wakeup gets all variables of an array.


  • 0

why we use oop concept for our programming

why we use oop concept for our programming

why we use oop concept for our programming

The question arises why we prefer OOP to Procedural programming. The first term we must be familiar with procedural programming; it is the way where we have to code it procedurally first we make all things must be collaborative and interactive and method oriented again and again we have to write all procedures to execute the programme and if i am not wrong the procedural programming was lenthy one and complicated one also . i am just giving you below an example of what procedural programming says to real world.

code example of procedural programming

<?
$user_input_field = $_POST[‘field‘];
$filtered_content = filter($user_input_field);
mysql_connect(“database_hostname”,”database_user”,”database_password”); //database
mysql_select_db(“database_name”);
$sql = “query”;
$result = mysql_query($sql);
while ($data = mysql_fetch_assoc())
{
process ($data);
}
process_user_input_field($filtered_content);
?>

now we come to example of oop

 

<?
$input_user_field = new field();
$input_user_field->field_user_input_field(); //filter the user inputs
$database = new datalayer(“mysql”); //data  layer,access point
$db->connect($dbconfig);//sql commant we are using
$query_result = $db->execute($sql);
ReportGenerator::makereport($query_result);
$model = new Postmodel($field->get_filtered_content());
$model->insert();
?>

every thing from above code is clear and comprehensive and understandable easily as oop is not going to be an tough way to learn.

oop is not more than just the term use for Object Oriented Programing.

the advantages of oop over procedural programming are as follows:

  1.  It is more secure than procedural programming
  2. It is more and far more stable than procedural programming
  3. It has top notch programming concept over procedural programming.
  4. It is easy to learn and remember your own made code over what is written in procedural programming.
  5. It leads us to faster development than procedural programming.
  6. It supports inheritance in fast oriented way.
  7. It supports encapsulation in fast oriented way.
  8. It supports polymorphism in fast oriented way.
  9. It supports abstraction in fast oriented way.
  10. In short, it is more self explanatory than what other procedural languages are.

  • 0

what is difference between overloading and overriding

Category : oop

what is difference between overloading and overriding

 

 

 

 

 

 

 

 

what is difference between overloading and overriding

 

overloading means when you want to load things or objects with different parameters

overriding means when you want to load things which have same parameters and working on a class.

overriding always needs class inheritance to load a class whereas overloading does not need a class inheritance.

and one more example is as follows

when you have defined different methods and these methods access same class and it does not require any kind of inheritance ; it is called overloading.

above statements show that there is great difference between them.

 in overloading different methods must inherit a class otherwise there would not happen any kind of polymorphism.



Fatal error: Call to undefined function weblizar_navigation() in /home/websolutionsdone/public_html/wp-content/themes/ielts-career/category.php on line 23