Jump to content


Reuseing Of Php Code


2 replies to this topic

#1 Guest_contact_bogomil_*

  • Guests

Posted 06 July 2004 - 03:13 PM

Hi folks I am asking my self how to find best decision for 're-use' PHP Code. I am working of an exapmple and will post here again.

If anyone have ideas, plase post them here.


All the Best
bogomil

#2 phpprogrammer

    Advanced Member

  • Members
  • PipPipPip
  • 453 posts

Posted 07 July 2004 - 12:24 PM

Dear Frineds,


First I want to share a small joke with you about Reuseing Of Php Code

One new guy came for interview and I asked him that what is code reusability , then he replied is using the some code written by another person. then I became :rotfl: :bounce:


Reusing of php code is comes when We uses some classes and interfaces which consists of methods,

if my project requires a credit card validation in 20 pages,

[CODE]
creditcardvalidation.php
-----------------------------

Class CreditCardValidation
{


function validatecreditcard()
{
if(validcard)
{
return 1;
}





}

#3 phpprogrammer

    Advanced Member

  • Members
  • PipPipPip
  • 453 posts

Posted 07 July 2004 - 12:34 PM

Dear Frineds,


First I want to share a small joke with you about Reuseing Of Php Code

One new guy came for interview and I asked him that what is code reusability , then he replied is using the some code written by another person. then I became


Reusing of php code is comes when We uses some classes and interfaces which consists of methods,

if my project requires a credit card validation in 20 pages,

[CODE]
creditcardvalidation.php
-----------------------------

<?php

Class CreditCardValidation
{

var $creditcardno;

function validatecreditcard()
{


if(validcard)
{
return 1;
}
else
{
return 0;
}

} // end of funciton


}// end of class

?>




creditcardvalidationusage1.php
-----------------------------------
<?php

include("crecreditcardvalidation.php");

$OBJCreditCardValidation= new CreditCardValidation();

$OBJCreditCardValidation->creditcardno=some number post of user

if($OBJCreditCardValidation->validatecreditcard())
{
echo "your card is valid";
}
else
{
echo "your card is not valid";
}


?>




creditcardvalidationusage2.php
-----------------------------------
<?php

include("crecreditcardvalidation.php");

$OBJCreditCardValidation= new CreditCardValidation();

$OBJCreditCardValidation->creditcardno=some number post of user

if($OBJCreditCardValidation->validatecreditcard())
{

do some online transactions

}
else
{
echo "your card is not valid";
}


?>







creditcardvalidationusage3.php
-----------------------------------
<?php

include("crecreditcardvalidation.php");

$OBJCreditCardValidation= new CreditCardValidation();

$OBJCreditCardValidation->creditcardno=some number post of user

if($OBJCreditCardValidation->validatecreditcard())
{
store the creditcard number into database

}
else
{
echo "your card is not valid";
}


?>



so I write the code in one class and I am reusing the code in other files.
If I want to change the business loginc of validating the creditcard just I need to do the changes in the creditcardvalidation.php page only.






regards,
bvsureshbabu





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users