Internet Computing T2

studied byStudied by 0 people
0.0(0)
learn
LearnA personalized and smart learning plan
exam
Practice TestTake a test on your terms and definitions
spaced repetition
Spaced RepetitionScientifically backed study method
heart puzzle
Matching GameHow quick can you match all your cards?
flashcards
FlashcardsStudy terms and definitions

1 / 110

encourage image

There's no tags or description

Looks like no one added any tags here yet for you.

111 Terms

1

Does OOP overloading apply in PHP

No, PHP is not a compiling language

New cards
2

How does PHP implement overloading

uses variable-length arguments (also called variadic functions) to accept flexible number of arguments

<p>uses <strong>variable-length arguments</strong> (also called variadic functions) to accept flexible number of arguments</p><p></p><p></p>
New cards
3

How does overrriding work in PHP

same as OOP

<p>same as OOP</p>
New cards
4

How to override inherited methods

by redefiining methods using same name (overriding) in child class and with the final keyword

<p>by redefiining methods using same name (overriding) in child class and with the <strong>final</strong> keyword</p>
New cards
5

Abstract classes vs methods

class: contains at least one abs. method

method: method that is declared but not implemented

New cards
6

Abstract Classes Rules

  • child class methods must be defined with same name

  • child class method must be defined with same or less restricted access

  • number of required arguments must be the same, but child class can have optional arguments aditionally

New cards
7

What are interfaces

defined in same way as a class, but says interface instead of class.

to implement interface, class needs to use implements keyword

New cards
8

Interface vs. Abstract Classes

  • interfaces cannot have properties, but abstract classes can

  • all interface methods must be public, while abstract classes can be public or protected

  • all methods in an interface are abstract, so abstract keyword is not necessary, but all methods in an abstract class do not have to be abstract

  • classes can implement an interface while inheriting from another class at the same time.

New cards
9

Methods that connect PHP to MySQL

MySQLi

PDO

difference: PDO suppords various databases and MySQLi supports only MySQL. MySQLi also a bit faster. PDO supports 12 different drivers, opposed to MySQLi (MySQL only)

New cards
10

MySQLi code demo

knowt flashcard image
New cards
11

PDO code demo

knowt flashcard image
New cards
12

create DB with MySQLi

knowt flashcard image
New cards
13

Create DB with PDO

knowt flashcard image
New cards
14

Create Table MySQLi

knowt flashcard image
New cards
15

Create Table PDO

knowt flashcard image
New cards
16

MySQLi Insert

knowt flashcard image
New cards
17

PDO Insert

knowt flashcard image
New cards
18

Prepared Statement MySQLi vs. PDO

knowt flashcard image
New cards
19

prepared statements procedures

  • prepare sql query with empty vals. as placeholders with “?” or variable name (ex. “INSERT INTO MyGuests VALUES(?, ?, ?)”)

  • bind values or variables to placeholders

  • execute query simultaneously

New cards
20

MySQLi prepared statement procedure

knowt flashcard image
New cards
21

benefits of using SQL prepared statments

  • useful against SQLi attacks

  • reduce parsing time since preparation is done only once

  • minimizes bandwidth to server since you need only params each time

New cards
22

PDO prepared statement procedure

knowt flashcard image
New cards
23

PDO vs. MySQLi

knowt flashcard image
New cards
24

What is PDO

an extension that defines lightweight consistent interface for accessing databases in PHP

New cards
25

What classes does PDO contain?

  • PDO class: represents connection between PHP and DB server

  • PDOStatement class: represents prepared statement and, after statement is exectured, an associated result test

  • PDOException class: represents error rasied by PDO (dont raise from ur own code)

New cards
26

Types of prepared statments

  • named parameters

  • positional parameters

New cards
27

when should you use prepared statments

  • SQL statements contain user inputs or SQL statments run repeatedly

New cards
28

When should you use direct execution APIs

SQL statements do not contain user inputs and SQL statments run one time

New cards
29

How to use direct execution (PDO statment)

$pdo→exec(…)

New cards
30

Steps for PDO prepared statement

  • two param methods (named param, positional param)

    1. $pdo→prepare(…)

    2. $pdo→bindParam(…)
      $pdo→bindValue(…)

    3. $pdo→execute(…)

New cards
31

SQL templates for named parameters and positional parameters

  • named parameters: the form :name

  • positional parameters: ?

New cards
32

PDO prepared syntax

PDO::prepare(string $query, array $options = []): PDOStatement|false

  • $query: a valid SQL statement template

  • $option: set attribute values for PDOSStatement object

New cards
33

bindValue() function

PDO::bindValue(string|int $param, mixed $value, int $type = PDO::PARAM_STR): bool

  • $param: for prep. statment with named placeholder will be in form :name , ? placeholder statements will be the 1-index position of param

ex

  • Example:

    $stmt1 -> bindValue (':name ','Ben’, PDO :: PARAM_STR );

    $email = ‘shaun@gmail.com';

    $stmt1 -> bindValue (':email ',$email );

New cards
34

bindParam() function

New cards
35

bindParam()

bool PDO::bindParam(string|int $param, mixed &$var, int $type = PDO::PARAM_STR, int $maxLength = 0, mixed $driverOptions = null): bool

  • ex

    • $name = 'Ben ';

      $stmt1 -> bindParam (':name’, $name ,PDO::PARAM_STR );

New cards
36

named parameter example

knowt flashcard image
New cards
37

positional parameter example

knowt flashcard image
New cards
38

difference between bindValue() and bindParam()

  • similar from user perspective, differ in implementation

  • bindParam() binds param exclusively to specified variable name, bound as reference

  • bindValue() binds value that could be a varaible, integer or string to parameter

New cards
39

Debug tools for PHP

  • visual studio

  • Xdebud

New cards
40

Debug techniques

  • dump variables to standard output (stdout)

  • switching error reporting level - update php.ini

New cards
41

main uses of PHP

  • server side scripting

  • requires: PHP parser, web server, web browser

  • PHP code not visible to browser users

New cards
42

how to define variables and check data types in PHP

variables start with $, case sensitive

var_dump() checks data types

New cards
43

Method for data type conversion

Settyype(mixed &$var, string $type)

<?php
$count = "5";
echo gettype($count); // before datatype conversion: $count is a string
settype($count,'int’);
echo gettype($count); // after datatype conversion: $count is an integer
?>

New cards
44

Comparision Operators in PHP

Operator

Name

Example

Explanation

==

Equal

$a == $b

Returns true if $a is equal to $b.

===

Identical

$a === $b

Returns true if $a is equal to $b and they are of the same type.

!=

Not equal

$a != $b

Returns true if $a is not equal to $b.

<>

Not equal

$a <> $b

Returns true if $a is not equal to $b.

!==

Not identical

$a !== $b

Returns true if $a is not equal to $b or they are not of the same type.

<

Less than

$a < $b

Returns true if $a is strictly less than $b.

>

Greater than

$a > $b

Returns true if $a is strictly greater than $b.

>=

Greater than or equal to

$a >= $b

Returns true if $a is greater than or equal to $b.

<=

Less than or equal to

$a <= $b

Returns true if $a is less than or equal to $b.

<=>

Spaceship

$a <=> $b

Returns an integer less than, equal to, or greater than zero, depending on whether $a is less than, equal to, or greater than $b.

New cards
45

how do Arrays in PHP work

  • indexed array

  • associative array (paired key → value)

New cards
46

accessing items in array with foreach

syntax: foreach ($array as $key => &$value)

New cards
47
<p><span>If we remove the sign “&amp;” in foreach, what the output will be? </span></p>

If we remove the sign “&” in foreach, what the output will be?

values inside array will not be modified bc $value is just a copy of each elemt, not reference to original element

New cards
48

PHP variable scopes

  • local

  • global

  • static

New cards
49

PHP anon function

$fn = function (int $x, int $y)

  • do not inherit variables from parent scope → need to use use keyword

  • can be assigned to variables, passed as arguments to other functions, or returned from functions.

$factor = 10;
$multiplier = function($x) use ($factor) {
return $x * $factor;
};
echo $multiplier(5); // Outputs: 50

New cards
50

PHP arrow function

$fn = fn (int $x, int $y)

  • automatically inherit variables from parent scope

  • used for simpler one liner functions

$factor = 10;
$multiplier = fn($x) => $x * $factor;
echo $multiplier(5); // Outputs: 50

New cards
51

function declaration

declare(strict_types=1)

New cards
52

how to accept variable number of arguments

function functionName(...$args) { ... }

New cards
53

superglobal variables

  • associative arrays that are always accessible, regardless of scope

  • provide information about server, request, and environment

New cards
54

nodejs

  • open source back-end javascript runtime environtment

  • allows developers to use javascript for server side scripting

  • event driven architecture capable of asynchronour I/O

New cards
55

how to start javascript code

<script>…</script>

New cards
56

is JS case sensitive

yes

New cards
57

how do JS comments work

  • supports both C and C++ style comments

  • any text between // and at end of line is treated as comment

  • any text between /* and */ is treated as a comment

New cards
58

how is JS data type determined

dynamicaly based on value stored

New cards
59

Difference between function_name and function_name() in
JavaScript

function_name refers to the function object while function_name() refers to

the function execution result.

New cards
60

display function exec results example

knowt flashcard image
New cards
61

scopes in javascript

  • block scope: decalred inside {} block with either let or const cannot be accessed outside the block

  • function/local scope

  • global scope

New cards
62

variable scope diference between PHP and JS?

New cards
63

ways to declare a javascript varaible

  • var - function scope

  • let - cannot be redeclared afterwards, have block scope

  • const - cannot be chaned after assigned valueble scope difference between PHP and JS?


New cards
64

what are identifiers in JS

unique names JS variables are identified by

New cards
65

JS hoisting

  • varaibles defined with var are hoiseted to the top anc can be initialized at any time

  • with let you cannot use a varaible before its declared

New cards
66

JS functions to extract string parts

  1. slice(start, end) - start, end are indexes

  2. substring(start, end) - does not accept negative indices

    • if start > end, substring will swap arguments

  3. substr(start, end) → DEPREACTED

New cards
67

how to replace parts of string in JS

replace(searchValue, newValue)

New cards
68

What kind of number does JS have

64-bit floating point

New cards
69

Symbol in JS

  • represents unique identifier

  • ever symbol call is guaranteed to return a unique symbol

New cards
70

how to create an object in JS

  1. using Object Literal/Initializer Syntax

    var p1 = { name:“John" }; // object literal syntax

  2. using new operator

    var p2 = new Car(‘BMW’, ‘red’); //Car can be either a function or a class
    such that an object

  3. using the Object() Constructor function with new keyword or create()

    var p2 = Object.create(car); // Object() constructor function

    p2.name = “John"; // property

New cards
71

JS object creation limitation

a property name that has a space or a hyphen, or that starts with a
number) can only be accessed using the square bracket notation.

New cards
72

what is a JS object property and types of properties

characteristic of an object, often describing attributes associated with data structure

  1. instance properties: hold data specific to object instance

  2. static properties: hold data shared among all other instances

New cards
73

what does a property have in JS

a name (string or symbol)

a value (primitive, method, or object reference)

New cards
74

how to access object properties JS

  • objectName.property

    • ex. person.age

  • objectName[“property”]

    • ex. person[“age”]

  • objectName[expression]

    • ex. x=”age”; person[x]

New cards
75

JS methods

JS methods can be located at value location in key:value

JS method is property containing function definition

New cards
76

how to access object methods JS

objectName.methodName()

New cards
77

JS accessors

gettters: get property()

setters: object.property = “x”

New cards
78

JS class

program code template for creating objects

class ClassName {
constructor() { ... }
method_1() { ... }
method_2() { ... }
...
}
//"constructor“ is a special method
// constructor does not have a name
// there is no destructor() in JavaScript

New cards
79

JS class example

knowt flashcard image
New cards
80

JS inheritance

uses extends, inhetits all methods from parent class

super() method in constructor meands parent property is called

New cards
81

JS encapsulation

  • public/private

  • by default all methods/vars are public

  • private members can be created using # prefix

<ul><li><p>public/private</p></li><li><p>by default all methods/vars are public</p></li><li><p>private members can be created using <strong>#</strong> prefix</p><p></p></li></ul><p></p>
New cards
82

getter and setter syntax

{get prop() { return property; }}

{set prop(val) { ... }}

  • Do not use parentheses when calling a getter (e.g., rect.area, not rect.area()).

  • get and set can be used both inside and outside of classes

New cards
83

getter example

class Rectangle {
constructor(height, width) {
this.height = height;
this.width = width;
}
get area() {
return this.height * this.width;
}
}
const rect = new Rectangle(5, 10);
console.log(rect.area); // Outputs: 50

New cards
84

setter examples

const language = {
set current(name) {
this.log.push(name);
},
log: []
};
language.current = 'en';
language.current = 'jp';
console.log(language.log); // Outputs: ['en', 'jp']

New cards
85

this keyword in JS vs PHP

JS:

  • this refers to object that is executing in curr function

  • in global scope, refers to global object

  • in functions, refers to hlobal object or undefined (nonstrict vs. strict)

  • in methods, refers to object that owens the method

  • in event handlers, refers to element that recieved event

  • in arrow functions, inherited from parent scope

PHP

  • this is used within class methods tp refer to current object instance

  • used to access properties and methods of class

  • cannot be used in static methods, since they are called on class itself and not instance

  • not used in global scope

New cards
86

function declaration vs function expression

declaration:

  • function declarations load before any code is executed,

  • hoisted on top of other code,

  • cannot define anon func

expresson:

  • function expressions load only when the interpreter reaches that line of code,

  • not hoisted,

  • can define anon func

<p><strong>declaration:</strong> </p><ul><li><p>function declarations load before any code is executed, </p></li><li><p>hoisted on top of other code, </p></li><li><p>cannot define anon func</p></li></ul><p><strong>expresson:</strong></p><ul><li><p>function expressions load only when the interpreter reaches that line of code, </p></li><li><p>not hoisted, </p></li><li><p>can define anon func</p></li></ul><p></p>
New cards
87

What are the basic syntax forms of JavaScript arrow functions?

param => expression

//ex
param => {
let a = 1;
return a + param;
}

(param1, paramN) => expression

//ex
(param1, paramN) => {
let a = 1;
return a + param1 + paramN;
}

New cards
88

arrow functions limitations

  • does not have its own bindings to this or super and should not be used as methods

  • does not have new.target keyword

  • noy suitanle for call, applu, and bind methods which rely on scope

  • cannot be used as constructors

New cards
89

What are the key differences between traditional functions and arrow functions?

  • Traditional functions use the function keyword, while arrow functions use =>.

  • Arrow functions are more concise, especially for single-expression functions.

  • Traditional functions are more versatile (e.g., can be used as constructors), while arrow functions are ideal for short, non-method functions.

New cards
90

what do JS function parameters not do

  • function definitions do not specify data types for parameters.

  • functions do not perform type checking on the passed arguments.

  • functions do not check the number of arguments received ←→ PHP

New cards
91

what are the arguments object in JS functions

array of arguments used when function called

New cards
92

default parameters in JS

if function is called with missing arguments, the missing valuesa re set to undefined and JS keeps running

New cards
93

how to invoke a function as a method of an object

objName.methodName()

ex. console.log(employee.fullName());

New cards
94

how to invoke function with a function constructor

new Function(functionBody)

new Function(arg1,…argN, functionBody)

New cards
95

call() method JS

predefined method of function objects

useful when you want to reuse a function with different objects or explicitly set value of this

  • function is not a method of object you want to use with

  • want to borrow method from one object and use with another object

New cards
96

call() method example

const person = {
fullName: function() {
return this.firstName + " " + this.lastName;
}
};

const person1 = {
firstName: "John",
lastName: "Doe"
};

// Using call() to set `this` to person1
console.log(person.fullName.call(person1)); // Outputs: John Doe

Here, fullName is a method of the person object, but we want to use it with person1. By using call(), we explicitly set this to person1, allowing the function to access person1's properties (firstName and lastName).

New cards
97

when to use call()

  1. borrowing methods

    const person2 = {
    firstName: "Jane",
    lastName: "Smith"
    };
    console.log(person.fullName.call(person2)); // Outputs: Jane Smith
  2. explicitly setting this

    function greet() {
    console.log("Hello, " + this.name);
    }

    const user = { name: "Alice" };
    greet.call(user); // Outputs: Hello, Alice

New cards
98

When is call() necessary in JavaScript, and when is it unnecessary?

  • Unnecessary:
    When a function is already a method of the object you're calling it on. Use object.method() directly.
    Example: employee.fullName().

  • Necessary:
    When you want to reuse a function with a different object or explicitly set this. Use function.call(thisArg).
    Example: person.fullName.call(person1).

New cards
99

JS apply() function

  • The apply() method is similar to call(), but it allows you to pass arguments to the function as an array (or array-like object).

  • It is used to invoke a function with a specific this value and arguments provided as an array.

synatx: functionName.apply(thisArg, [argsArray]);

New cards
100

JS bind() function

  • The bind() method creates a new function with the same body as the original function but with a fixed this value.

  • Unlike call() and apply(), bind() does not immediately invoke the function. Instead, it returns a new function that can be called later.

New cards
robot