Enhancing PHP for Better Reuse: Mechanisms and Case Study

colonteeΛογισμικό & κατασκευή λογ/κού

4 Νοε 2013 (πριν από 3 χρόνια και 10 μήνες)

95 εμφανίσεις


B.Comp. Dissertation








Enhancing PHP for Better Reuse: Mechanisms and Case
Study








By


Xu Wei Jie
















Department of Computer Science


School of Computing


National University of Singapore


2008/09




B.Comp. Dissertation


Final

Project Report




Enhancing PHP for Better Reuse: Mechanisms and Case
Study






By


Xu Wei Jie








Department of Computer Science


School of Computing


National University of
Singapore


2008
/09









Project No:

H094730

Advisor: A
ssoc
P
ro
f

Jarzabe
k

Stanislaw

Deliverables:


Report: 1

Volume


Source Code: 1 CD
-

1
-


Table of
Contents

Abstract

i

Keywords: generative techniques, meta
-
programming, software ruese, maintenance

i

Acknowledgements

ii

Chapter 1

1

Introduction

1

1.1

Project Objective and Scope

1

1.2

Project Contribution

2

1.3

Report Structure

2

Chapter
2

3

Background

3

2.1

Managing Software Complexity and Reuse

3

2.2

XVCL (XML based Variant Configuration Language)

3

2.3

PHP (Hypertext Preprocessor)

5

2.4

PHP+ library/framework

5

Chapter 3

7

PHP+ library specifications and improvement highlights

7

3.1

PHP+ Syntax

7

3.2

Difference
s between PHP+, PHP and XVCL

10

3.3

Improvements highlights of the PHP+ library

10

3.3.1

I
MPLEMENTATION OF PP
_
MESSAGE
()

10

3.3.2

A
SSIGNING A VARIANT N
UMBER OF INSERT STAT
EMENTS

11

3.3.3

G
ENERATING TARGET COD
ES IN PHP

11

3.3.4

D
IRECTORY ISSUES
(R
ELATIVE AND
A
BSOLUTE ADDRESS HAND
LING
)

12

3.3.5

$
SAMELEVEL ATTRIBUTE
IS NOW SUPPORTED IN
PP
_
ADAPT
()

12

3.3.6

A
PPENDING TO OUTPUT F
ILES

12

3.3.7

H
ANDLING RECURSIVE AD
APTATIONS

13

3.4

Correctness of the PHP+ library implementation

13

3.4.1

D
EFINITION OF PP
_
ADAPT
(),

PP
_
INSERT
(),
PP
_
INSERT
_
BEFORE
()

AND
PP
_
INSERT
_
AFTER
()

13

3.4.2

D
EFINITI
ON OF PP
_
SET
()

AND PP
_
GET
()

18

3.4.3

D
EFINITION OF PP
_
MESSAGE
()

19

Chapter 4

21

PHP+ and Project
Collaboration Environment

21

4.1

Overview of PCE

21

4.2

Clones in PCE

21

4.3

Mixed Strategy and its strengths

22

Chapter 5

27

Evaluation of the PHP+ library

27

5.1

Case Study: Project Collaboration Environment

27

5.2

Introduction of PHP+ constructs and what it does that PHP cannot

27

5.2.1

Use of PHP+ variables

27

5.2.2

Use of PHP+'s adapt

28

5.2.3

Use of PHP+'s inserter and pp_break function

29

-

2
-


5.3

Benefits and Tradeoffs of using PHP+

32

5.3.1

Benefits

32

5.3.2

Tradeoffs

33

Chapter 6

34

Conclusion

34

References

iii

Appendix A

iv

Case Study Deliverables

iv




































i


Abstract


Companies face a great deal of complexity in huge scale systems thus the need for reuse
mechanisms to better modularize code structures. We
apply

generative techniques to build
these mechanisms. The reuse mechanisms in XVCL are extensible and sought after.

PHP+
itself is modeled after XVCL’s success [1]. The objective of implementing PHP+ is to
emulate XVCL using a common language PHP. We want to offer reuse capabilities to the
PHP community with minimum learning curve.


PHP is a popular language and tool
for Web Application development. PHP supports dynamic
page generation which is helpful in reuse. However, PHP does not have full
-
fledged
variability management mechanisms to handle multiple similar product variants, in reuse via
Software Product Line (SPL)

approach. XVCL provides reuse mechanisms as required for
SPLs, but does not have any PHP capabilities for building Web Applications. In this project,
we attempt to implement XVCL reuse mechanisms in PHP itself. Such integrated PHP
-
XVCL solution we term PH
P+. Following up on earlier encouraging results with PHP+, in
this project, we refine PHP+ prototype mechanisms implemented earlier to build a
production
-
quality PHP+ system. We argue about the correctness of our implementation with
respect to XVCL specifi
cations. In addition, we provide a systematic study to demonstrate the
benefits of implementing reuse mechanisms in common language such as PHP.



Keywords: generative techniques, meta
-
programming,
software ruese, maintenance






ii




Acknowledgements


I wou
ld like to thank my supervisor Associate Professor Stanislaw Jarzabek and Damith C.
Rajapakse for the
opportunity,
motivation

and resources

they
have given

me. A/P Stanislaw
Jarzabek has
been especially helpful and
provided me
with
interesting insights and

expertise

into the field of

framing software reuse.



[http://en.wikipedia.org/wiki/Frame_Technology_(software_engineering)]
.


In addition, I would like to thank Chris Henry and Xue Yinxing for the help and guidance
they have shown me throughout the enti
re project period.






























1


Chapter 1


Introduction


PHP is a
popular
web scripting language used to ge
nerate dynamic html forms. The

files are
generally
embedded with HTML and PHP tags. To enhance
the
aesthetics

of code, there
are

template engines
written out there to allow the separation of business logic (say, getting data
from a database) from the presentation of data.



PHP’s potential lies in expedient web development. There
are

PHP frameworks and
libraries
complementing PHP’s existing functionality

that
assist PHP programmers
in dealing

with
code complexity

and

build
ing

large scale systems. However,
majority of the PHP community
still
holds the belief

that a programmer’s best practices
,

skill and e
xperience helps build

a
complex yet robust

PHP system

infrastructure better than using any existing framework or
library
.


XVCL (XML based Variant Configuration Language) is a language that is developed with
full fledged variability management mechanisms
to handle multiple similar product variants,
in reuse via Software Product Line (SPL) approach. However, XVCL does not have any PHP
capabilities for building Web Applications. Hence, we build an integrated PHP
-
XVCL
solution termed PHP+ in an attempt to fus
e XVCL reuse mechanisms into PHP.


In this project, we present about how we refine the prototype mechanisms in the first version
of PHP+ to build a production
-
quality PHP+ system. Secondly, we argue its correctness with
respect to XVCL specifications. Last
ly, we provide a systematic study to demonstrate the
benefits of implementing reuse mechanisms in common language such as PHP.


1.1

Project
Objective

and Scope


PHP+ is a
library/framework

written by
Henry
[1]

to model
the reuse mechanisms embedded
in

XVCL

(XML
-
based

V
ariant

Configuration Language
)

to offer reuse functionality
.
The
objective of our project is to

motivate

the PHP community to
use PHP+

so they can
leverage
on
PHP+
’s

reuse
mechanism
s

and

spread the meta
-
programming, frame
-
based reuse
2


technique
s.

T
his

fuels our motivation
to select PCE

(Project Collaboration Environment)

as
a
case study
to

provid
e

a systematic study

to demonstrate the benefits of implementing reuse
mechanisms in PHP
.



1.2

Project
C
ontribution


Henry
has rewritten the Java
Buffer Library

[4
]

in PHP+ context to

demonstrate the
capabilities of

its
reuse
mechanism
s

that maps user
designed

specifications into the intended
target language.


In this project, w
e
s
elected
PCE (Project Collaboration Environment)

to migrate over

to

a
PHP+ framework.

W
e highlight improvements that
have

been
implemented
to
refine
the
PHP+
library to build a production quality PHP+ system

and argue its correctness with
respect to XVCL specifications
.
Last of all, w
e
evaluat
e

the PHP+
library
on the bas
is of the
case study
selected
to
demonstrate the benefits of implementing reuse mechanisms in PHP
.



We
shall
discuss
more about the

PCE platform

in Chapter 4.


1.3

Report
Structure


The rest of the
report

is organized in the order as follows
.

In Chapter 2, we introduce the
background and literature of
software complexity and

reuse, XVCL, PHP and PHP+. In
Chapter 3, we discuss the syntax of PHP+, its correctness
with respect

to XVCL
specifications
and improvements highlights of the library. In C
hapter 4, we discuss the case
study of PCE (Project Collaboration Environment) with PHP+ examples and the mixed
strategy

approach
. In Chapter 5, we evaluate the PHP+ library with
a systematic study to
demonstrate the benefits of implementing reuse mechanis
ms in common language such as
PHP
. We conclude in Chapter 6.

3


Chapter
2

Background

2.1

Managing Software Complexity and Reuse


We
observe

that across
several
software systems, there exist
lot
s

of structural similarities
(repetition patterns of any type or granularity) as discussed in Jarzabek’s paper
[
4
]
.
Thus, it
fuels
the motivation

to d
evelop meta
-
structures
in

XVCL

frames
.

We
shall
discuss the history
and literature of XVCL in section 2.2.



Due to the existence of structural similarities, the concept of software reuse becomes so
attractive wh
ere

developers can
use to
cut down

on
repetitive

development
.

We
shall
discuss
briefly about the
SPL (S
oftware

P
rod
uct
L
ine
)

approach
.
SPL approach cen
ter on domain
specific reuse within a family of software systems that are pretty much alike. The main idea
of
a
SPL

approach
is to

establish a PLA (Product Line Architecture)

[
3
]
. A PLA is
a
base

of
reusable
components

in the form of a framework
.

We
generate

PL

(Product Line)

members
using

the PLA
through product derivation
. Product derivation is

a

cycle

of
selecting,
customizing
, integrat
ing

and validat
ing

the components
.

W
e
kick start

this cycle
by selecting
variant features for a product. This is t
he architecture XVCL
builds
.
PHP+
is
a library wr
itten

using PHP (a common language)
by
Henry

[1]

to model
the

reuse mechanisms

in XVCL
.



We shall elaborate more on XVCL and PHP+ in section 2.2 and 2.3.

2.2

XVCL (XML based Variant Configuration Language)


XVCL
(XML based Variant Configuration Language)
is a solution developed for software
reuse and maintenance
.

XVCL, in general, express
es

program structures in the form of meta
-
level representations
(x
-
frames)

with variations points within
.

These x
-
frames

ar
e processed
thru

the XVCL processor to generate output files in the target language.


Essentially,
XVCL

contains
a set of
commands
that
performs

useful
reuse
mechanism
s
.
We
shall note some of the notations used here.
To begin with
, t
he
most basic
meta
-
comp
onents of
XVCL are
term as x
-
frames and these x
-
frames
are the

building blocks of
the PLA

(
w
e also
4


define

the PLA as an
x
-
framework in the current context
)

as what we have discussed
above

in
section 2.1. We achieved component reuse by
writing

template x
-
fr
ames
containing reusable
code fragments
in the target language and writing another set of specification x
-
frames to
specify the
code generation
flow control and parameterization of variation
points

in the
template x
-
frames
. The
se

x
-
frames are “adapted”
to
an actual code in the target language
from each other thr
ough the

<adapt> statements

invoked. A
fter which
, the frames

are
linked

through

ancestor
-
descendant relations

(
as

illu
strated in Figure 1

below
)
.
Command
statements

like

<insert> and <break>

are invoked in specification and template x
-
frames respectively to
manage and manipulate the variation
points
we want our
product line members

to
have
.
Besides the 2 statements as discussed above, <set>, <value
-
of> and <remove> are also
statements we
coul
d
use to achieve the
different
level
s

of
variation
s

we intend to have by
introducing variant variables.

V
ariables
defined

and assigned with values
are accessible to the
current x
-
frame and all
of
its descendants.
Figure 1
extracted from [1
2
] as

below descr
ibes an
x
-
framework for a family of Editors
.




Figure 1 x
-
framework describing a family of Editors


Other statements like <while>, <select>
/
<option>
,

<ifdef> and <ifndef>
are for control flow
usage
and designed for

the XVCL programmer to use.

They are intuitive to understand
be
cause they are

similar
in concept with
other programming language constructs

(
i.e.

C)
.


To
understand
how XVCL
works
, we
shall
discuss about the XVCL processor. The processor

facilitates the product derivation
using

the
PLA(x
-
framework)
as input
and
generates the

product line members

as output. To modify any variations we intend to have in the
structure

of the reuse codes, we
would
need to modify the x
-
frames
within

the PLA(x
-
framework).


5



To
read

more about XVCL

developm
ents
,
visit

xvcl.comp.nus.edu.sg


2.3

PHP

(Hypertext Preprocessor)

PHP is a powerful server
-
side scripting language for creating dynamic and interactive
websites.

It generally runs on a
web server

(generally the Apache server)
,
parsing

PHP code
within
its

delimiters (
i.e.

<?php and ?>)
as input and creating
web pages

as output.

In
addition, PHP has all the characteristics of a proper general purpose programming language.
With the release of version 4.3,0
, it
supports
a new
SAPI

type (Server Application
Pro
gramming Interface)

termed CLI for
C
ommand
L
ine
I
nterface

(
http://sg.php.net/features.commandline
)
.
PHP

is widely
-
used

and often a good alternative to

Microsoft's ASP. It supports ISAPI and can be used with Microsoft's IIS on Windows
.

From a collective pol
l
, PHP are
mostly
used
by the community
to develop applications like
online
forums, shoppin
g carts, online communities and
CMS

(Content Management Systems)

such as the
ever
popular Joomla

(
http://www.joomla.org/
)
.

PHP programmer
s

do

face
increasing
software complexity

nonetheless
. Some of
the
complexities
arise from

internationalization, accessib
ility, security, state and etc
.

PHP
programmers

generally

believe that a programmer’s
best practices,
skill and experience
are

needed to manage software comp
l
exity other than depending on
reuse
mechanisms.

Currently, they have no available framework to offer
them
XVCL
-
like
reuse capabilities and
PHP+ serves to fill that gap.


To
read

more about PHP

developments
,
visit

www.php.net


2.4

PHP+ library
/framework


PHP+ is a library/framework written by
Henry
[1]
to create XVCL
-
like frames

that are parsed
into

PHP
’s

Command Line Interface

and
having its output

emitted
to
source codes
files in the
target language
instead

of

a web server
.
PHP+

models its functions from

XVCL
commands

to
offer

programmers
reuse capabilities.

On top of that, PHP+ has in its garrison the full
6


expressive power of PHP.

The motivation be
hind writing
the
PHP+
library
is to
emulate

reuse
mechanisms
embedded in
XVCL
using a
c
ommon

language.



We
shall
discuss more about PHP+
library specifications and improvement highlights
in
Chapter 3.




























7


Chapter
3

PHP+ library specifications and improvement highlights


3.1

PHP+ Syntax


PHP+
models

the

reuse mechanisms

in
XVCL using PHP as
its implementation
language.
We
illustrate a list of these PHP+ functions and
their
XVCL command equivalent
.


I.

pp_adapt($frame, $output_dir=null, $output=null, $samelevel="no")



Located in:
In phpplus_functions.php

Equivalent
in

XVCL :
<
adapt>


Usage
: To adapt x frames

Parameters

1.

$frame

is the
name of
frame specified to be adapted.
The path specified in this
parameter could be

relative to the directory where the
parent frame is invoked from or
it could be absolute
.

2.

$output_dir

is the
name of
output directory to write the file
s

to. It can be an absolute
or relative path. Default
value
is null. If it is null

or an empty string
, it build
s

onto the
relative
path incrementally.

3.

$output

is the name of the
output
file to be written to. Defaul
t
value
is null. If it is null

or an empty string
, the child frame
is

adapted
into the parent frame.

4.

$samelevel

specifies if the PHP+ variables
set
in the child frame
is to
be accessed

in

the parent frame.


“yes” to do so and “no” not to. Default
value
is
“no”.



Note:
You can specify a variant number of insert statements and the pp_adapt function will
still handle it
(i.e
. pp_adapt(“frame.pp”,pp_insert(“break1”,””),

pp_insert(“break2”,””)); )


II.

pp_set ($name, $value)



Located in:
In phpplus_functions.php

Equivalent in XVCL :
<
set
>

8


Usage
: To
set PHP+ variables

Parameters

1.

$
name

is the
name of the PHP+ variable.

2.

$
value

is the
value of the PHP+ variable
.
$value can be
of

(
array

|
textual
-
content
)


Note:

These variables are stored in

2 associative arrays to ens
ure correct implementation.
Please refer to [1]
section 6.5.1
for details


III.

pp_
g
et ($name)


Located in:
In phpplus_functions.php

Equivalent in XVCL :
<
value
-
of
>

Usage
: To get/return PHP+ variables by name

Parameters

1.

$
name

is the name of the PHP+ variable.


IV.

pp_
remove

($name)


Located in:
In phpplus_functions.php

Equivalent in XVCL :
<
remove
>

Usage
: To remove PHP+ variables by name

Parameters

1.

$
name

is the name of the PHP+ variable.


V.

pp_break($name, $default_insert=null)


Located in:
In phpplus_functions.php

E
quivalent in XVCL :
<
break
>

Usage
: To specify break (variation) points

Parameters

1.

$
name

is the name of break point.

2.

$default_insert
is the default code snippet to be processed at the break point if there
9


are no insert
s
that match it
. Default
value
is null.
$default_insert

can be

of


( textual
-
content

| <+
php+
functions
+> )


Note:

We need to be careful about special characters when dealing with PHP string literals
(
http://sg.php.net/language.types.string
).

In addition,

HEREDOC and NOWDOC [in PHP
5.3.0] are very useful syntax to
assign

multiple
code
lines to
$default_insert
.


VI.

pp_insert_
before
($name,$insertion)

VII.

pp_insert
($name,$insertion)

VIII.

pp_insert_after($name,$insertion)


Located in:
In phpplus_functions.php

Equivalent in XVCL :
<
insert
>
; <insert
-
before
>; <insert
-
after
>

Usage
: To specify insertions
at
,
before
or
after
the break points

Parameters

1.

$
name

is the name of break point.

2.

$insertion
is the code snippet to be
injected

at the break point
.
$
insertion

can b
e

(
textual
-
content

|
<+ php+
functions
+>

)


Note:

We need to be careful about special characters when dealing with PHP string literals
(
http://sg.php.net/language.types.string
). HEREDOC and NOWDOC [in PHP 5.3.0] are very
useful syntax to
assign

multiple
code
lines to
$insertion
.


IX.

pp_message($value,

$continue =
”yes”
)


Located in:
In phpplus_functions.php

Equivalent in XVCL :
<
message
>

Usage
: For debugging

purpose
s

Parameters

1.

$
value

is the
debugging message to be specified
.

2.

$
continue

specifies
if execution is to be continued

from the point of function
invocation
. “yes” to continue and “no” to terminate execution. Default
value
is

yes”
.



10


3.2

Difference
s

between

PHP+
, PHP and XVCL


PHP is a first class meta
-
language whose language constructs are
processed

by the PHP
parser

within any set of opening and closing delimiters (i.e. <?php ?>) to
produce
output via a
web server or PHP’s CLI (
C
ommand
-
L
ine
I
nterface
).

The language

allows

prog
rammers to
have great expressive power in writing
programs
.

On the contrary
,
XVCL is
developed

upon
the concepts of framing software reuse

using

XML

(Extensible Markup Language)

and JAXP
(Java API for XML Parsing)
.

XVCL
implements reuse

mechanisms into tag
s

that are parsed
by JAXP.

The parser generates an event for each occurrence of the beginning of a tag, the end
of a tag
, data

in between tags
and etc. Custom event handler methods are

written to interpret
the events whenever they are invoked
.



In contras
t to both
, PHP+
is

a
library
of functions designed with the intention of providing the
programmer XVCL
-
like reuse capabilities using PHP’s CLI to
emit output to source files in
the target language
.
PHP

serves
only
to complement PHP+ with its flow control constructs to
provide
looping and selection/option
functionality
.

Unlike XVCL
tag based commands
,
PHP+ functions provides flexibility to do more given the full expressive power of PHP.

3.3

Improvements
highlights of

the PHP+
library


In this section, we discuss the improvements made to PHP+ prototype mechanisms
.

3.3.1

I
MPLEMENTATION

OF PP
_
MESSAGE
()


We have implemented the
PHP+ function pp_message()

which is the
equivalent of
XVCL’s <message>
command
.
For its specifi
cation, please refer to Section 3.1
above.
This

function

facilitates debugging

and can

be used to evaluate the contents of
a variable
or more. Evaluated contents will be processed into text ad printed to
console for display via the STDERR stream
(
http://sg2.php.net/wrappers.php
)
.

Whereas, output emitted from the frames are written to actual generated files via the
STDOUT stream
(http://sg2.php.net/wrappers.php)
.

It is important to note that
d
ebugging
output
does
not affect frame output.

Furthermore
, user gets to specify
“yes” to continue frame processing or “no” to terminate when invoking pp_message.

11


3.3.2

A
SSIGNING

A
VARIANT NUMBER OF IN
SERT STATEMENTS


Inside

the parameters of the

pp_adapt function, user is able to specify
0 or more

pp_insert statements local to the adapt itself. The
advantages

of

using this approach
include not having to specify a

separate

Inserter object
prior to each adapt
invocation
.

When
ever

a pp_adapt function is invoked,
a local
I
nserter object is
instantiated

within
its

scope.

Subsequently
, pp_insert statements if any are passed in
as

parameters
are

processed to
load th
is

Inserter

object with insertion contents.

Thereafter
, th
is Inserter

object
is

saved and destroyed.

The above mentioned process is done
locally in

the
scope of

pp_adapt.

Therefore, we
should

not be concerned

with
implications
about
having
a globally defined

Inserter
object
.

Furthermore, pp_insert statements invoked
outside of pp_adapt’s scope

does

not
cause

any side effects.


Below list

a sample code snippet
to
illustrate
how you can do the above mentioned


pp_
adapt (
'frame.php',

pp_
insert (
'
editable_container
',

"

Here are the container links



And something else



And yet something else

And yet other thing

"

),

pp_insert(“
editable_s
howExisting”,"another insert"),

pp_inse
rt_after(“editable_showExisting”
,"
and yet another insert
")
);


3.3.3

G
ENERATING TARGET COD
ES IN
PHP


The original implementation of
PHP+
produce

output file
in
many
target language
s,

such as

JAVA,
C
/C++

or others
. Howe
ver,
producing

output files

in PHP
can
cause
quite a
problem
as PHP
use

the same delimiter tags
as

PHP+
.

Hence, an execution of
PHP+ in the CLI may not be able to differentiate between the two, resulting in an
erroneous execution.

Thus f
or PHP+, we
re
-
design

the opening tag delimiter
to be
<+

and the closing tag delimiter
to be
+>

respectively
. This is done so as to not confuse

them
with
the usual
PHP delimiter tags
like

<?php

and
?>
. A
routine

is written to
12


perform
a pre processing step to switch PHP d
elimiter tags to
_TO_

and _TC
_

respectively.
If short tags are enabled, ‘
<?

tags
shall be

switch
ed

to _TOS_.
Subsequently
, we

switch PHP+ delimiter tags to PHP
delimiter tags

in the frames
before the
y

are parsed into the command line
interface
for process
ing

to generate
output files in the target language
.
Last but not least
, a

post processing step is
performed
to return all the tags in the frames to its original state.

Below shows a
command line

of how to run a PHP+ solution.


C:
\
...> php
pp_processor
.php pce.spec.php


3.3.4

D
IRECTORY ISSUES

(R
ELATIVE AND
A
BSOLUTE
ADDRESS

HANDLING
)


In the pp_adapt functions,
$frame

and
$outdir

attributes could handle relative and
absolute addresses. For addresses assigned to
$frame
, PHP+ increment
s

the path of
the adapting frame
relative

to the directory in which the parent frame resides. For
addresses assigned to
$outdir
, PHP+ builds an
incrementing relative path in

the order
of how the frames are
being
adapted

down the framework
.
This is also how

the
<adapt> command in
XVCL

behaves
.
Pl
ease read XVCL specifications [
7
] for more
details
.

It is a good feature to have because user need not s
pecify extremely long
addresses
for

the path of the directory or file when there exist complex directory
structures.

To add on, PHP+ supports the
integral
u
se of
the
forward or backward
slash in the address
specified

which makes it platform
-
independent
.


3
.3.5

$
SAMELEVEL ATTRIBUTE
IS
NOW
SUPPORTED IN PP
_
AD
APT
()


This attribute takes a value of “yes” if PHP+ variables
set
in the
adapted
child frame
are

to be

raised
and accessed in

the parent frame
. Default
value
is “
n
o”.

If $samelevel
is “yes”, c
hild frame is included in the parent frame and
$output

attribute
is

ignored.
This is an unusual form of adaptation when
output
is
not emitted to a file
.


3.3.6

A
PPENDING TO
OUTPUT

FILES


This is a small glitch which was unnoticed in the first
prototype

of
PHP+. It has
now
been fixed.
At the moment,

if PHP+ emits output to a target file for the first time

and

This is the php
specification frame

13


file does not exist,
the file
shall
be created and overwritten with the output.
Subsequently, if PHP+ emits output to the same file during the same run
, the output
shall

be appended onto the file.


3.3.7

H
ANDLING RECURSIVE AD
APTATIONS


PHP+ does not allow recursive adaptations. In other words, a frame cannot adapt
itself.
There are 3 scenarios as follows. In scenario 1, the calling frame adapts itself.
In scenario 2, the

adapt statement appears in the context of

an insert statement like the
example show
n

below. In scenario 3,
the current
frame ‘A’
adapts

frame ‘B’

and
subsequently, frame ‘B’ adapts frame ‘A’. PHP + exit
s

gracefully for
all 3 scenarios
with errors prompted
.



//
recursive_adapt
.
spec.
p
h
p

<+ include("./phpplus/phpplus.php"); +>


<?php

<+ pp_adapt("
recursive.pp
",

pp_insert(‘break’,

<<<INSERT

<+ pp_adapt(‘
recursive.pp
’);+>

INSERT

));+>


//
recursive
.pp

<+ include("./phpplus/phpplus.php"); +>


<+ pp_break(‘break’);+>


3.4

Correctness
of the PHP+ library

implementation



In this section, we argue about the correctness of PHP+ library implementation
in contrast

to
XVCL
formal
specifications

[
7
].
W
e
shall also
discuss about the challenges met in th
e
process.


3.4.1

D
EFINITION OF
PP
_
ADAPT
(),

PP
_
INSERT
(),
PP
_
INSERT
_
BEFORE
()

AND
PP
_
INSERT
_
AFTER
()


These PHP+ functions are
often used

together
.

We shall inspect their functionalities and
examine them in contrast to XVCL’s commands.



14


First of all
,
we
shall
study
XVCL
’s <adapt>
command
from the definitions

stated
below

(extracted from [
7
] page 16)
.


adapt := <
adapt x
-
frame
="
frame
-
file
-
name
" [
outdir
="
dir
-
name
"]

[
outfile
="
output
-
file
-
name
"] [
samelevel
="
yes
-
no
"] [
once
= “
yes
-
no
”]>


dir
-
name

|
frame
-
file
-
name|

output
-
file
-
name

:= Expression

adapt
-
body := ( insert | insert
-
before | insert
-
after )*


3.4.1.1

F
ILE NAMES OF FRAMES


frame
-
file
-
name

is the name of the frame to be adapted. XVCL evaluates
this attribute

as an
expression
.

Its rules specify that it
can
be assigned

a file name, a relative path or an absolute
path.


How PHP+ and XVCL handle
frame
-
file
-
name


1.

If it is a

file name

(i.e.
pp_frame
.pp)
, the processor

look
s

for the frame in the current
directory. Else if it is a relative path, the processor look
s

for the frame in the directory
relative to where the parent frame resides. Else, the processor look
s

for the frame in the
absolute path
assigned with
.


2.

In XVCL cont
ext, if the extension of the frame is not specified, XVCL adapt
s

the frame if
a match is found
. Otherwise, XVCL adapt
s

the frame with ‘.xvcl’ extension.
PHP+ do
es

not handle

situations where the extension

of the file name is not given (i.e.
pp_frame
withou
t ‘.pp’
)
.

N
onetheless
, it is a good practice to include a
n integral extension

‘.spec.php’ or ‘.pp’ for PHP+ frames.


3.

Both
XVCL and PHP+ do not handle recursive adaptations. In other words, a frame
cannot adapt itself. PHP+
exit
s

gracefully with errors prom
pted
if it does so.


3.4.1.2

D
IRECTORY NAMES OF
OUTPUT DIRECTORIES


dir
-
name

is the name of the directory where the generated
output
files are
saved

to
.

XVCL
evaluates this attribute as an expression. Its rules specify that it can
be assigned

a relative
15


path or an absolute path.


How PHP+ and XVCL handle dir
-
name


In XVCL context, if a
directory name

is specified

and the directory does not exist,
XVCL
create
s

it. PHP+ behaves the exact way XVCL does by incrementing the relative path in the
order of how the frames are being adapted. In other words, if the directory name is not
specified

(
i.e.

null or empty string)

when invoking
an
adapt
statement in

the child f
rame
, the
directory name specified
when invoking an adapt statement
in the parent frame
shall
be used

as the output directory
. If an absolute path is specified
in
dir
-
name

when invoking an adapt
statement
in the parent frame, this
absolute
path
shall
be used
as the output directory and all
descendant frames
shall
append their own relative paths to it and output accordingly
. If a
relative path is specified
in
dir
-
name

when invoking an adapt statement
in the parent frame, it
behaves
the same as XVCL

with

the exception
al behavior

that the relative path
is

appended
to a folder named ‘src’

in the current directory
. (i.e
.

if the path is ‘./frame X/’, the output
directory
is

concatenated as
‘./src/./frame X/’)



3.4.1.3

F
ILE NAMES OF OUTPUT
FILES


output
-
file
-
name

is the name of the
output file
. XVCL evaluates this attribute as an
expression. Its rules specify that it can
not
be assigned a
relative path.


How PHP+ and XVCL handle
output
-
file
-
name


XVCL frames have extensions ‘.xvcl’
whereas
PHP+ frames have

extension
s

‘.spec.php’ for
specification frames and ‘.pp’ for template frames. It is a good practice to provide frames
with extensions so we can differentiate them visually.


There are 3 scenarios as follows.

I
n scenario 1
,

when outputs are emitted to the

file

output
-
file
-
name

for
the first time and the file name exists, the file
is

deleted
, created

and
outputs

are
saved into it
. In scenario 2
,

when

the file does not
exist
,
the file

is

create
d

and
outputs
are

saved into it
. In scenario 3
,

when

the output
is emitted
to the same file in the same run, the
output
shall
be appended to
the contents of that file
. PHP+ does not
handle

scenario 1.


16




Challenges met




It is
feasible

to implement a table that counts the number of times a specific file

is

written to in 1

processing
run

and save it into a data structure

for access
. This
enable
s

PHP+

to support the functionality in scenario 1 above
.

It will be a good feature to
have. Currently, we think it is optional

because t
he whole generated solution can be
deleted befo
re we execute

the next processing run
again
.


3.4.1.4

R
AISING VARIABLES


same
-
level

specifies if variables
set
in child frame are to be raised and accessed in the parent
frame. XVCL evaluates this attribute as a “yes
-
no” expression. Default
value
is “no”.


How PHP+ and XVCL handle
same
-
level


In PHP+ context, t
he child frame
is adapted

using the PHP directive

include

(
http://sg.php.net/include/
)

and
emulates the
exact

behavior in XVCL.




Challenges met




This feature
could

be
particularly useful if
variables are evaluated as expressions.
However, PHP+ variables are currently evaluated as values

only
.


3.4.1.5

I
GNORING SUBSEQUENT A
DAPTS IN CHILD FRAME
S


once

specifies if subsequent adapts
of the specified frame
are ignored or not. XVCL evaluates
this
attribute as a “yes
-
no” expression. Default
value
is “no”.


How PHP+ and XVCL handle once


I
t is not supported
in PHP+
at the moment.


3.4.1.6

W
HAT
COMPRISES

AN
ADAPT
-
BODY


Adapting frames
and managing insertions

into break points are
2 main reuse techniques
of

XVCL.
adapt
-
body

comprises a mix
ture

of

insertions that
match

the break points in the
frames

and textual content
.


17


How PHP+ and XVCL handle adapt
-
body


In
both
XVCL
and PHP+
context,
adapt
-
body

comprise
s

of
textual content and
0

or more
insert statements.
In XVCL,
the insert statements
are
named

<insert>,

<insert
-
before> and
<insert
-
after>
.
They

are equivalent to PHP+

functions
pp_insert, pp_insert_before and
pp_insert_after respectively.

To add on, i
nsert statements
invoked
are
local
ized

to the adapt

statement
. In XVCL context, insert statements are valid
only
within the

starting and ending
tags of the

<adapt> command. In PHP+, insert statements are parsed into pp_adapt as
arguments.
I
f
insert statements

are
ever
placed
outside the scope of pp_adapt, no side effects
are

incurred.



3.4.1.7

W
HAT IS BEING INSERTE
D AND HOW IT WORKS I
N THE BACKGROUND


W
e
shall
study
XVCL’s <insert>, <insert
-
before>
,

<insert
-
after>

and <break>

commands
from the definitions
stated
below
(extracted from [
7
] page 16)
.


insert := <
insert break
="
break
-
name
">

Insert
-
Content

</
insert
>

break
-
name
:= Expression


insert
-
before := <
insert
-
before break
="
break
-
name
">

Insert
-
Content

</
insert
-
before
>


insert
-
after := <
insert
-
after break
="
break
-
name
">

Insert
-
Content

</
insert
-
after
>


Insert
-
Content := ( textual
-
content | break | adapt | set | set
-
multi | select |

ifdef | ifndef | value
-
of | message | while | remove )*


break := <
break name
="
break
-
name
">

Break
-
Content

18


</
break
>


break
-
name :=
Expression


Break
-
Content := (textual
-
content | adapt | set | set
-
multi | select | ifdef | ifndef |

value
-
of | message | while | remove)*


Insert
-
Content

specifies the type of contents that can be inserted

into
Break
-
Content

as
above
.
break
-
name
is

evaluated as
an
exp
ression
.
For detailed information about
the XVCL
constructs

that can be assigned to
Insert
-
Content

and

Break
-
Content
, please
refer to

the
XVCL specifications [
7
].


How PHP+ and XVCL handle
insertions


In XVCL context, it is
intuitive

to the user

from the definitions above
on
how insertions are

inserted to break points
.

<insert> will insert contents into the matching break point. <insert
-
before> and <insert
-
after> will insert contents before and after the matching b
r
eak point
respectively.
Break
-
C
ontent

is the default content

to be processed if no insert statements
matches the break point. If insert statements within <adapt> are directed
to
the same break
point, the contents
shall
be concatenated. In PHP+ context, we model the same behavior

using pp_insert(), pp_insert_before(), pp_insert_after() and pp_break()
.

Please refer to section
3.1 for
the function
specifications.

However, with regards to

the contents to be inserted, these
XVCL constructs (set
-
multi | select | ifdef | ifndef | while)

are not handled
because they do
not have a PHP+ equivalent.
The insert contents

comprise of

textual content and PHP+ codes
embedded within <++> tags.
HEREDOC and NOWDOC [in PHP 5.3.0] are useful syntax to
handle multiple lines of insertions
.


In addition
, do be
mindful

of the special characters

(
http://sg.php.net/language.types.string
)

in
PHP that
need to be escaped with a slash when specifying the contents to be inserted.

3.4.2

D
E
FINITION OF PP
_
SET
()

AND

PP
_
GET
()


These PHP+ functions are used to set and get variables via names specified. We shall inspect
their functionalities and examine them in contrast to XVCL’s commands.


19


3.4.2.1

PHP+ variables


PHP+ variables are very useful
.

They

can be set in any frame to be

retrieved by descendant
frames

subsequently
. Their values
could
be used to append to paths and filenames, print out
to
source files

and much more
depending on

how you wish to use them.
To add on,
PHP+
variables set in ancestor frames should not and
does
n
ot get overwritten in descendant frames.


How PHP+ and XVCL handle variables


<set> and <value
-
of> are XVCL commands that are used to set and
emit the values of

variables.
To get the value of the variables,

XVCL evaluate expressions which contain the
names of variables.
(i.e. expression
?@module?
evaluates

the
value of the
variable with
the
name ‘module’
)

<value
-
of>
command
simply takes in expressions, evaluate them and emit
the values
evaluated
to output.
I
n PHP+ context, pp_set() and pp_get() are their equivalents.
Currently, PHP+ does not evaluate expressions. (i.e. to print out the value of the variable
‘module’, we need to code like this <+ echo pp_get(‘module’);+>)


In PHP+
,
we
restrict

variables set in

ancestor frames
from

get
ting

overwritten in descendant
frames

by using

a two tiered symbol table that comprises of
2 PHP associative arrays
. For
details, please refer to section 6.5.1 of [1].




Challenges met




Expressions are
especially
useful when we are dealing with variables. Currently,
PHP+
does

not handle expressions but we think it
is feasible
.


3.4.3

D
EFINITION OF PP
_
MESSAGE
()


This PHP+ function is used for debugging purposes mainly.


3.4.3
.1

Debugging


In
programming
, debugging f
acilities are utmost important because the programmer need to
know which
section

of the program is
not showing a correct behavior
. The most frequent
debugging activity
is to find out what value does a

variable
hold at some point of time
.

20



How PHP+ and XVCL
does debugging


In XVCL context, the <message> command prints the value of the evaluated expression
pa
rsed

to screen. It is often used to track variable values and trap error situations. Within the
command, the user can specify if executi
on is to be continued or terminated
from the point of
command invocation
given an expression that evaluates to either

yes


or

no

. In PHP+,
pp_message
models the exact behavior
. Please refer to section 3.1 for its syntax

and section
3.3.1 to understand i
ts functionality
.


In Chapter 4 and 5, we
shall
provide a systematic study of PHP+ using PCE (Project
Collaboration Environment)
























21


Chapter 4

PH
P+ and Project Collaboration Environment

4
.1

Overview

of PCE


PCE (abbreviation for Project

Collaboration Environment) is a generic web application used
to facilitate management of projects. The version of PCE we are working with manages all
kinds of activities related to project planning and execution. In its domain, there are 6 main
entities,
namely Project, Staff, Product, Task, Notes and File. Figure 2 below is a domain
model extracted from [
9
] to illustrate the entity types and relationships that are amid them.






In this project, w
e are working only with the UI layer of PCE. The business logic and
database layers are not included in
the scope of
our case study
. In
section

4
.2

and 4.3
, we
discuss more about the clones in PCE

and unifying these clones using an approach termed
‘mixed s
trategy’ at the meta
-
level representation

based on the
reuse

technique
s

of PHP+ [1]
.



4
.2

Clones in
PCE


Figure 3

b
elow

is a
feature diagram

we
extracted

from [
9
]
to illustrate the
structural
similarities

(clones)

and variations between PCE modules.

A module may have 1 of 3 forms
of relationships with another module. It can be a simple association (i.e. a staff performing a
task), an aggregation type association (i.e. a project has notes) or a composition type
Figure 2 Domain Model of PCE


22


association (i.e. a task has sub tasks).






Each PCE module is a combination of features given in the diagram above.
This diagram
represent
only
the higher level inter module variations
. There are other lower level variations
and also intra module
similarities

not shown here (i.e. copy and edit action being similar

with
the exception that copy action creates a new record
whereas
editing simply overwrites
)
.


4.3

Mixed
Strategy and its strengths


Mixed Strategy is a
n approach composing of a

hybrid of
conventional technologies with
meta
-
programming to
unify

clones in code structures. Mixed strategy
depicts

that meta
-
programming complements conventional technology

in nature

and not competing
. Figure
4

below
illustrates
the unification process
.




Figure
4

Unification of clones via the mixed strategy

Figure 3 Feature Diagram of PCE


23



From
Figure 4

above
, we
have a
n

overview

of
using

the mixed strategy approach
and

PHP
+
to

unify clones on the meta
-
level into generic reusable components

(or
termed
product
variant
s
)
.
To begin with, a

PHP+ meta
-
component is
a unit
of codes
that contains
generic
structures

with

variations

within
.
W
e store these
reusable
meta
-
components
in
to

template
frames (with extensions ‘
.
pp’).

Template frame “
display[M]Controller
.pp” as described b
elow

illustrate
s

h
ow we
delineate

the

differences
between modules.


//display[M]Controller.pp

<+ include("./phpplus/phpplus.php"); +>


<?php

<+ pp_adapt(".
\
Entity
\
securityCheck.pp");+>


require_once("
<+ echo pp_get("module");+>
TableGateway.php");

require_once("display
<+
echo pp_get("module");+>
ViewHelper.php");


$id = $_REQUEST['id'];

$helper = new display
<+ echo pp_get("module");+>
ViewHelper($module_name, $id);

<+ echo pp_get("module");+>
TableGateway::incrementReadCount($module_name, $id);


include ("display
<+ echo pp_ge
t("module");+>
View.php");

?>


The
first
line of code that is h
ighlighted
in the
frame
above
include
s

the PHP+ library
in order
to instantiate
the file
as a frame. Those
lines of code
highlighted
subsequently

are the
points
of variations

between clone instances.

To understand

the mechanics of the code

within the <+
+> delimiter tags

better
,
please

refer to
section 3.1
on PHP+ syntax
.


Templates frames are generic and adaptable
.

These frames are

used to
produce

variants of the
reusable com
ponent
s

in
different

reuse contexts.
We adapt a child frame from a parent frame
by invoking the
pp_adapt()
function
(
function specifications
in
Section 3.1
)
.
This function
is
similar but works
very
differently from the include directive in PHP

(We show thei
r
difference in section 5.2.2)
.
W
e highlight a line of code in p
arent frame
READ.pp
as
described
below
to
illustrate

how the
child

frame
display[M]Controller
.pp
above is

adapted.


//READ.pp

<+ include("./phpplus/phpplus.php"); +>


<+
pp_adapt(".
\
Entity
\
display[M]Controller.pp",null,"display".pp_get("module")."Controller.php");+>


<+ pp_adapt(".
\
Entity
\
display[M]View.pp",null,"display".pp_get("module")."View.php");+>

24



<+ pp_adapt(".
\
Entity
\
display[M]Details.pp",null,"display".pp_get("mo
dule")."Details.php");+>


<+
pp_adapt(".
\
Entity
\
display[M]ViewHelper.pp",null,"display".pp_get("module")."ViewHelper.php");+>


B
y a
pplyin
g a mixed strategy approach
and PHP+ to building
PCE
, we

derive the following
miniature
framework

in

Figure
5 as

illust
rated
below.
Please

note that it
depicts
only
a subset
of
the entire framework structure
.

Figure

5

also
help
s

us
to
understand
more
about

what we
have discussed earlier
.

SPC (Specification frame) denotes the root of the framework
hierarchy where the most context sensitive information
is

customized.








Figure 5

A subset of the PCE

framework

in PHP+ representation




25


In addition, we are able to
reduce

the number of mod
ification sites.
We
illustrate this

with a
mock Product Line (PL) whose members are similar PHP files
. Each file contains a security
check routine and
a simple
html table.
For readability, the modification sites are shown in
bold and italics

with increased

font
in Figure 6

as shown below





Figure 6

Reducing the number of

modification sites using PHP+ frames


From Figure 6

above, we
do not need to

modify the

source code files

separately
. We

modify

only

the frames
accordingly
to reflect changes in code
design
. The figure

above

illustrates
only the
scenario for 4

files but
we

may
have to manage

10 to 30 such files in system
s with
great complexity
. By
reducing

the number of
modification sites, we
simplify the process of

code maintenance
and reduce

the occu
rrence
s

of update anomalies.


To summarize, by applying PHP+ and a mixed strategy approach,

we are able to reap the
benefits of a non redundant system representation without compromising on the other goals
of system design
or being ho
ld back by programming

language rules.

26



In Chapter 5, we
shall
evaluate the PHP+ library and demonstrate its benefits as well as
tradeoffs
.





















27


Chapter 5

Evaluation
of the PHP+ library

5.1

Case Study: Project Collaboration Environment


In the process of
applying reuse generative techniques in PHP+, we do face tradeoffs.
However, applying these techniques to project application gives off benefits in the short and
long run as well. In this chapter, we apply PHP+ to building PCE and describe the benefits
and

tradeoffs that entails with it. Furthermore, we shall discuss the differences of what PHP+
constructs can do on top of PHP.


A quantitative

evaluat
ion

of
applying
PHP+ to maintain a framework of PCE reuse
components

creates

the table below
.
T
able

1

illustrates

obvious reduction
s to the line of
codes, number of files and the total file size involved
.





Lines of Codes

Number of files

Total file size (bytes)

PHP+ solution

1457

40

47,188

PCE Portal

solution

8353

119

220,544

%
in r
eduction

82.56

66.39

78.60


Table 1: Comparison between the 2 solutions

5
.2

I
ntroduction of PHP+ constructs and what it does that PHP
ca
nnot



In this section, we gradually introduce PHP+ constructs and define the differences between
PHP+ and PHP
.


5.2.1

Us
e

of PHP+ variables


A PHP variable can be
defined with

global scope and it get
s

stored in PHP's very own
$GLOBALS associative array. Any change or reference to the variable
shall

be done
globally
.
We see t
his
a
s a very dangerous operation as the programm
er need to second
guess if a variable is changed in subsequent involved files or in functions. As for the other
28


scopes of a PHP variable, their values get lost when they exit their scope unless they are
static. Even so, static variables do not impact gener
ative programming.


On the contrary
, a

PHP+ variable is stored in 2 associative arrays
that form a 2 tiered
symbol table
to ensure that a variable set in an ancestor frame does not get overridden in a
descendant frame.
This implementation models a correct

behavior of the adapting
mechanism in PHP+. To add on,
PHP variables cannot be removed
unlike

PHP+
variables
.


5.2.2

Us
e

of PHP+'s adapt


In PHP, we can often use normal functions and conditional statements to generate
output
files in the target language

using the clones. However, it gets very complicated when the
logic flow and the clones are all written into a single file. Thus, we
would

want to use
PHP's include

()

directive

and output buffering
to segregate the clones from the logic flow
into individu
al
template frames

to make it more elegant.

There are limitations though.
Variables are hard and cumbersome to inherit down to the included templates using the
keyword ‘global’. Include()

directive

itself is also not able to spawn multiple child frames
ins
tances
to create the x
-
framework we wanted.


In addition, w
e are
also
unable to
model

code insertions at certain variation points like
what XVCL's <break> and <insert> can.



PHP+'s use of adapt resolves
these issues neatly
. Clones can be written into many

manageable template frames and th
ese frames
shall be
adapted from the

root
down to the
leaf level to establish

the x
-
framework
.
S
pecification frames
contain mainly the logic
flow (i.e. variant parameters and control statements) to
facilitate and process t
he clones in
the template frames and generate reuse
source
code files
.
With t
he x
-
framework
, it

makes
the code base

easy and practical
to maintain
.


PHP+’s adapt

is
also
able to spawn multiple child instances by means of PHP’s system()
function and seriali
zes both PHP+ variables and objects (i.e. Inserter objects, we
shall
29


mention more about it
in section 5.2.3
) so the child frames can
inherit
them to use. We
can see the difference using include() and using adapt() in
the points mentioned above
.


5.2.3

U
s
e

of PHP+'s inserter and
pp_
break
function


In the reuse context, there
are

often files where there are extra methods or code sections
to be inserted at certain points within them. This
provides

generating reuse files great
flexibility and added ease of code

maintenance. PHP itself can hardly do this with simple
and straight forward buil
t

in functions.
Furthermore, m
anaging associative arrays to
handle the insertions

induce
more
human coding errors. Code maintenance
becomes

a
very big problem because the arrays introduce complexity and hard to understand code.


Thus, the Inserter is a very practical useful PHP object that encapsulates inserting
capability and introduces simplicity of using it. The object itself allows per PH
P CLI
process to have all the needed insertion information at any one time. The
pp_break

statement

can be used within php
+ frames

to allow the adapt function as described above
to map all the
matching
insertions. Thus, we do not need conditional if else co
nstructs to
handle them. Conditional constructs
creates messy and hard to trace program flow
.


We shall investigate these problems using a small subset extracted from the
implementation of

the

PCE
framework
to understand it visually
.













30


PHP
implementation

of a mini PCE





Points to take note of a PHP
implementation:

1)

Global variables may get modified at child nodes

and

need to be declared with
keyword

global
’ to be accessed
.

2)

Modeling

insertions at variation points

(i.e. break points) with
associative arrays and
if else constructs can get messy and produce hard to trace program flow
.

3)

PHP o
bjects are globalized and shared among nodes
.

4)

To
produce output files

in PHP, php tags
need to

embedded between ‘single quotes’
(i.e
. <?php
echo ‘<?php
’;

?>
)

so the command line
interface
does
not parse them.















31


PHP+
implementation

of a mini PCE





Points to take note of a PHP+
implementation

1)

PHP+ variables that are
declared and set

in ancestor frames would not be overwritten
in child frames.

2)

Adaptation can be done in 2
forms
. The contents

of the frames

either get processed
into
the
current frame or into a file. Each
PHP+
adapt instance spawn
ed

has its own
adapt_inserter

object and PHP+ variables inherited from above.

3)

Modeling insertions are done thru the
functions
pp_
break (
…)
and

pp_
insert (
…)
.
This

eliminates messy if else constructs and enhances readability of code
.

Overall, it
makes

t
he code structures in PHP+ frames elegant and neat.

4)

To
produce output files

in PHP,
a routine is executed

to perform
an extra
preprocessing step to switch
PHP and PHP+
tags interchangeably
. After which the
frames are parsed thru the command line inter
face

to produce output

files

in the target
language
. Lastly, the frames are retu
rned to their original
state
by performing

a post
processing step
. There
are

no side effects

incurred
.

To add on, shorts tags are also
handled.



32


5
.3


Benefits
and
Tradeoffs
of using PHP+


In this section, we briefly mention the
benefits
and
tradeoffs
of
using PHP+.



5.3.1

Benefits


1.

In PHP+, we do not have to
learn

new notation

to
facilitate
reuse

in a product line.

On top
of that
,

we

have access to the
full expressive

power of PHP at the meta
-
level (PHP+)
.

2.

PHP+ provides the full
expressive
power of
the i
mplementation language PHP

at the
meta
-
program level.
On the
contrary
, each extension
in XVCL
must be separately
implemented.

With the additional edge,

PHP+

creates new opportunities for meta
-
level
which have yet to be explored.

(i.e.
to

implement the <
message> command in XVCL,
custom event handlers are written to interpret generated events for the start of
the tag, end
of the

tag, data in
-
between and etc. On the contrary, PHP+’s pp_message is
simply
a
PHP
function
which we could specify the parameters a
nd function body.
)

3.

PHP+ files are generally smaller due to the compactness of the syntax

and code sizes are
greatly reduced. The semantics expressed in the frames
greatly
enhances
program

understanding

(i.e.
enables

the programmer

to
comprehend how differe
nt features affect
program components)
.


4.

PHP+ is cross platform enabled

on Windows
, UNIX and
all flavors of
Linux etc.


In addition, PHP+ provides all the capabilities of XVCL:


1.

To manage multiple product variants (Product Lines), explicating commonalitie
s and
handling variant features specific to different products,

2.

To represent any group of similar program structures as a generic, adaptable meta
-
component.

3.

PHP+ greatly
reduces

the risk of update anomalies by
reducing

the number of
modification sites

(
as
illustrated in Figure 6

of section 4.2)
.

4.

The expressiveness of PHP+ to describe
look
-
alikes

and
variations

in code structures
makes the
choice

of applying a modification to clones
across the board

decidable.


33


5.3.2

Tradeoffs


1.

PHP+ has yet the capability to
evaluate

expressions.

2.

PHP+

does not ha
ve

DTD validation and verification capabilities

like XVCL does
due to
the fact that

XVCL is developed based on
the
XML platform
.

3.

Dealing with
special

characters like $ or “ in strings can

be quite a problem

because we
need to
add a
slash to escape else the command line
inter
face

shall

prompt parsing error
s.

4.

Expressing program
codes

with PHP+ meta
-
structures and
target

language
is an

arduous
task unlike designing of a conventional program.

































34


Chapter
6

Conclusion


Using a systematic study, we have demonstrated the feasibility of expressing XVCL meta
-
level mechanisms in PHP. Such an extended PHP we call PHP+. We demonstrated the merits
of PHP+ to unify clones in
a web application such as PCE. We believe that these generative
reuse techniques shall benefit the IT community greatly to maintain their code base
effectively. The mixed strategy approach and its generative reuse techniques do not pertain
only to XVCL. Th
e PHP+ library is a PHP
-
XVCL integrated solution where the generative
reuse techniques used in XVCL are brought over to a common language such as PHP. Thus, it
is intuitive to infer that we can duplicate the success model to other common languages.


We hav
e also discussed about PHP+ syntax and the significant improvements modified to it
to make the solution a production quality PHP+ system. Following, we highlighted the points
of how PHP+ differs from PHP constructs to apply generative reuse techniques and
evaluate
the pros and cons involved. Last of all, we evaluated the benefits and tradeoffs of the PHP+
library.


We believe that there are yet a lot more we can achieve with meta
-
level programming which
have not been explored. In the future work, we pla
n to explore possibilities of embedding
reuse generative mechanisms in other common languages and do experimental validation of
benefits of using PHP+. In addition, we want to show formal equivalence of PHP+ and
XVCL mechanisms. Our ultimate goal will be t
o promote PHP+ to PHP community for
applications in Product Lines.




iii


References



1.

Chris Henry (2007/08).
Utilizing A Common Language A
s

A Generative Software
Reuse Tool

2.

Clements, P, and Northrop, L. Software Product Lines:
Practices and Patterns,
Addison
-
Wesley, 2002

3.

Deelstra, S., Sinnema, M. and Bosch, J. “Experiences in Software Product Families:
Problems and Issues during Product Derivation,”
Proc. Software Product Lines
Conference
,
SPLC3
, Boston, Aug. 2004, LNCS 3154, Sp
ringer
-
Verlag, pp. 165
-
182

4.

Jarzabek, S.
(July 2007)

Software Reuse Beyond Components with XVCL

5.

Jarzabek, S., & Li, S. (2006). Unifying clones with a generative programming
technique: a case study.
Journal of Software Maintenance and Evolution: Research
and
Practice
, 18 (4), July, 2006, 267
-
292.

6.

Jarzabek, S., & Zhang, H. (2001). XML
-
based method and tool for handling variant
requirements in domain models.
5th IEEE International Symposium on Requirements
Engineering

(pp. 166
-
173), Toronto, Canada, August, 2001
.

7.

National University of Singapore (NUS) (2004).
XML
-
based Variant Configuration
Language (XVCL) Specification
, 2.07
edition
. From http://sourceforge.net/project/
showfiles.php?group_id=58966

8.


PHP (Hypertext Preprocessor)
http://www.php.net

9.


Rajapakse, D.C. and
Jarzabek, S. “
Practical Limits of Applying Dynamic Page
Generation Techniques in Web Application Design: a Trade
-
off Analysis
,”

10.

Rajapakse, D.
C. and Jarzabek, S. “
Using Server Pages to Unify Clones in Web
Applications: A Trade
-
off Analysis
,” Int. Conf. Software Engineering, ICSE’07,
Minneapolis, USA, May 2007, pp. 116
-
125

11.

Wong, T.W., Jarzabek, S., Myat Swe, S., Shen, R. and Zhang, H.Y. “
XML
Implementation of Frame Processor
,”
Proc. ACM Symposium on Software

12.

XVCL

(XML
-
based Variant Configuration
Language
)
http://xvcl.comp.nus.edu.sg












iv


Appendix A

Case Study Deliverables


The deliverables consists of the following:

1)

PHP+ source code (./phpplus/)

2)

Project Collaboration Environment

PHP+ implementation (./
PCE_PHPPLUS
/)

3)

A

README file
(
./
pce_PHP+_readme.doc
)

4)

Testing Codes (./phpplusTest/)

5)

A mini PHP
vs.

PHP+ implementation
example
(./
phpplusEx
/)


To
use
the PHP+ solution, you need to have PHP Command Line Interface installed in the
p
rogramming environment you are comfortable with

(you can download from
http://www.php.net/downloads.php
)
. To run the
solution
,
you can
double click

on
the
windows
batch file

in the directory where the solution resides

provided you are working in a
windows environment.



The generated
output files

shall

appear
in

the directory

.
/PCE_PHPPLUS
/src
unless specified
otherwise in the specification frame

pce.spec.php
.