Moving from procedural to OOP

General discussions related to php

Moderators: macek, egami, gesf

tonellma
New php-forum User
New php-forum User
Posts: 1
Joined: Thu Mar 06, 2014 2:35 am

Moving from procedural to OOP

Postby tonellma » Thu Mar 06, 2014 3:31 am

Hi, simple question from a newbie on mixing procedural and oo PHP (if it is possible).

I have a site with several pages that call a function located in a separate file

eg:

function callMe($szQuery){ echo 'I was called'; };

and it all works well, I can call it saying callMe("a SQL query");

now if I move it into a class:

class myQuery{

public static function callMe($szQuery){

echo 'I was called';
}

}

$n2 = new myQuery;

$n2->callMe("a SQL query");

Works all well, but the following (the old call) does not

callMe("a SQL query");

I don't really want to change all the pages, but I assume I will have to ... if I do, are there any suggestions on the best way to deal with this.

Thanks

PLDavidC
New php-forum User
New php-forum User
Posts: 4
Joined: Sun Mar 16, 2014 11:26 pm
Location: Poland - Wroclaw

Re: Moving from procedural to OOP

Postby PLDavidC » Sun Mar 16, 2014 11:33 pm

I'm afraid you're doing it wrong. If you have static method you must call it like "ClassName::method()".

Basing on your example your method must be called like

Code: Select all

myQuery::callMe("a SQL query")


Return to “PHP General”

Who is online

Users browsing this forum: No registered users and 2 guests

cron