MV Your Way - PHP Edition

Imagine trying to attract a new PHP developer to a job where you'll be training them to do mvBASIC work. They have to learn a new command line, a new programming language, and a new database. What if we made some of that easier by letting them bring some of their things into our home.

In the last issue, we use FUNCTION to make mvBASIC easier for us, the existing developers. We can also use the same trick to welcome our new friends inside.

PHP, like every other language, has a vast number of commands. We'll focus on some core ones for now. We'll start with date handling.

<?php
$idt=gregoriantojd(1,13,1998);
echo jddayofweek($idt,1);
?>

We could teach them to do it our way, and they should learn that eventually. That would leave them with something like:

idt = iconv('01/13/1998','D')
print oconv(oconv(idt,'DWA'),'MCT')

Instead, we could make two functions like:

FUNCTION gregorianotjd(month,day,year)
idt = iconv(month:'/':day:'/':year,'D')
return idt

FUNCTION jddayofweek(idt,mode)
begin case
case mode = 0
dow = oconv(idt,'DW')
case mode = 1
dow = oconv(oconv(idt,'DWA'),'MCT')
case mode = 2
dow = oconv(oconv(idt,'DWA'),'MCT')[1,3]
return dow

And what we did here works for other commands. Lets' re-invent file handling their way. PHP has several ways, we can start with file_get_contents and file_put_contents.

FUNCTION file_get_contents(thePath)
* thePath = /<filename>/<itemname>
theFname = oconv(thePath,'g1/1')
theIname = oconv(thePath,'g2/1')
*
theRecord = '-1':@AM:'not found'
open theFname to theHandle then
read theRecord from theHandle, theIname else null
end
return theRecord

FUNCTION file_put_contents(thePath,theRecord)
* thePath = /<filename>/<itemname>
theFname = oconv(thePath,'g1/1')
theIname = oconv(thePath,'g2/1')
open theFname to theHandle then
write theRecord on theHandle, theIname
end
return

Keeping going like that and they can code in our mvBASIC using their syntax. What we've done here can be extended to a large percentage of their commands. Yes, they will still need to use PRINT instead of ECHO but our mvBASIC will look better to their eyes. I do not advocate making this a long-term strategy, but putting a little of the familiar in our world makes it more inviting to others.

CHARLES BAROUCH

Charles Barouch is the CTO of HDWP, Inc. He is also a regular contributor to International Spectrum Magazine, a former Associate Editor for both Database Trends and for Gateways Magazine, a former distance learning Instructor for CALC. He is presently the Past President of the U2UG. Mr. Barouch has presented technology and business topics in front of hundreds of companies, in a wide range of product and service categories. He is available for on-site speaking and consulting engagements in and out of the United States.

View more articles

Featured:

Jul/Aug 2018

menu
menu