/    Sign up×
Community /Pin to ProfileBookmark

Need help in: OOP in PHP: beginner

Hi
just now i learned to create a classes in php.
after saving the file with extension .inc. where to store the file & how to call that class file in php.

eg:
mynewclass.inc:

class mynewclass{
function(—-
——)
{
}
}

calling.php :
how to call the class file here:

pls expain with some egs
so that its wasy to understand for me.

reply
pats

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@bokehDec 20.2005 — Give the included file a php extension; it better for security. If you still want the .inc you could use [I]filename.inc.php[/I] You can store your includes anywhere on the server file path that you can access (including non-public directories) or in the includes directory. My example assumes the include is in the same directory as the script calling it.[code=php]include('mynewclass.inc'); // i'd give this file a .php extension
$variableName = new mynewclass;[/code]
Copy linkTweet thisAlerts:
@Reli4ntDec 21.2005 — Yep.

The anytime you need it in the script thereafter just do [code=php]$variableName->functionName()[/code]
OOP is great and once you get used to it you'll be moving a lot of your scripts to these very portable classes.
×

Success!

Help @pats spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...