I have checked the PHP source code and can not find the "require" function.
I only found a piece code relatives to it on main/main.c from line 976
switch (EG(current_execute_data)->opline->extended_value) {
case ZEND_EVAL:
function = "eval";
is_function = 1;
break;
case ZEND_INCLUDE:
function = "include";
is_function = 1;
break;
case ZEND_INCLUDE_ONCE:
function = "include_once";
is_function = 1;
break;
case ZEND_REQUIRE:
function = "require";
is_function = 1;
break;
case ZEND_REQUIRE_ONCE:
function = "require_once";
is_function = 1;
break;
default:
function = "Unknown";
}
Do you know which file defines the "function"?
Related
Hy,
I got switch case inside function when but when i call it, i got error Undefined Variable and i don't know why (i use PHP 8)
private function getIDFromBrand() {
switch ($this->brand) {
case "Niky":
$id = 1;
break;
case "Pumo":
$id = 4;
break;
case "Coke":
if ($this->typecoke== 0) {
$id = 2;
} else {
if ($this->typecoke== 1) {
$id = 3;
}
}
break;
case "Tomato":
$id = 5;
break;
case "Riles":
$id = 6;
break;
case "TEST":
$id = 7;
break;
}
return $id; // Error Undefined variable $id
}
When i declare $id at the top of my function, like
$id = null
or
$id = 0
The switch doesn't update it, so it will return null or 0, it will return the declared value.
Your switch statement has no default branch, so if $this->brand is, say, "Stack Overflow", it will not run any of the statements, and $id will never be set.
See the PHP manual for the switch statement:
A special case is the default case. This case matches anything that wasn't matched by the other cases.
Similarly, if $this->brand is "Coke", but $this->typecoke is, say, 42, it will not match either of the conditions in that branch.
switch ($this->brand) {
case "Niky":
$id = 1;
break;
case "Pumo":
$id = 4;
break;
case "Coke":
if ($this->typecoke== 0) {
$id = 2;
} elseif ($this->typecoke== 1) {
$id = 3;
} else {
$id = -1; // WAS PREVIOUSLY NOT SET
}
break;
case "Tomato":
$id = 5;
break;
case "Riles":
$id = 6;
break;
case "TEST":
$id = 7;
break;
default:
$id = -1; // WAS PREVIOUSLY NOT SET
break;
}
Hello im trying to make an object as learning task which takes a number and calculate it three times and echos every step.
<?
// neues Objekt der Klasse erzeugen
$stringManager = new StringManager();
// output String initialisieren
$meinString = "";
$zahl = "100";
$stringManager->setMeinString($meinString);
$stringManager->setZahl($zahl);
// Schritte ausführen
for ($i=1; $i<=3; $i++) {
$stringManager->machSchritt($i,$zahl);
}
// String ausgeben
echo $stringManager->getMeinString();
// Klasse StringManager
class StringManager {
var $meinString;
var $zahl;
function StringManager() {
}
function machSchritt($welchenSchritt,$zahl) {
switch ($welchenSchritt) {
case 1:
$zahl + 50;
break;
case 2:
$zahl / 2;
break;
case 3:
$zahl * 5;
break;
default:
break;
}
$this->append("schritt".$welchenSchritt." fertig...");
$this->append("Zahl:".$zahl." ");
}
function append($what) {
$this->meinString .= $what;
}
//function append($what) {
//$this->zahl .= $what;
//}
function setMeinString($value) {
$this->meinString = $value;
}
function getMeinString() {
return $this->meinString;
}
function setZahl($value) {
$this->zahl = $value;
}
function getZahl() {
return $this->zahl;
}
}
?>
My output is: "schritt1 fertig...Zahl:100 schritt2 fertig...Zahl:100 schritt3 fertig...Zahl:100"
But I expect it to be "schritt1 fertig...Zahl:150 schritt2 fertig...Zahl:75 schritt3 fertig...Zahl:375
Please help me find what im doing wrong.
your problem is between this lines:
$zahl + 50;
break;
case 2:
$zahl / 2;
break;
case 3:
$zahl * 5;
if you want to increase/manipulate the variable $zahl so you have to use it:
$zahl += 50;
break;
case 2:
$zahl /= 2;
break;
case 3:
$zahl *= 5;
btw: your code is deprecated.
class StringManager {
var $meinString;
var $zahl;
function StringManager() {
}
}
should replace with
class StringManager {
private $meinString;
private $zahl;
public function __construct() {
}
}
update:
ah, now i understand, you need to work with your value.
so use this instead:
$this->zahl += 50;
break;
case 2:
$this->zahl /= 2;
break;
case 3:
$this->zahl *= 5;
$this->append("Zahl:".$this->zahl." ");
But it would be better, to use your setter (with typecasting) and getter methods.
warning
your code looks like php4 code. php4 is not supported since 2008 (http://php.net/eol.php).
I created a php script that uses a case and switch for dynamic content info. Everything works but I cannot get it to show the default page. I have searched all of stackoverflow and google and cannot seem to find out why my default in the switch wont load. I have tried other methods such as include('page.php');
<center><div class="dropdown">
<button class="dropbtn">TICKERS</button>
<div class="dropdown-content">
CRZ
FFT
GHG
GLH
IAN
IMH
IN
LAG
LIB
LXX
MDM
MJ
MMJ
NF
PUF
SL
SUN
TBP
THC
TNY
VGW
VP
VRT
</div>
</div></center>
<BR>
<?php
if(isset($_GET['page']) && $_GET['page']!=""){
$page = "";
switch ($_GET['page']) {
case 'crz':
$page = "crz.php";
break;
case 'fft':
$page = "fft.php";
break;
case 'ghg':
$page = "ghg.php";
break;
case 'glh':
$page = "glh.php";
break;
case 'ian':
$page = "ian.php";
break;
case 'in':
$page = "in.php";
break;
case 'lag':
$page = "lag.php";
break;
case 'lib':
$page = "lib.php";
break;
case 'lxx':
$page = "lxx.php";
break;
case 'mdm':
$page = "mdm.php";
break;
case 'mj':
$page = "mj.php";
break;
case 'mmj':
$page = "mmj.php";
break;
case 'nf':
$page = "nf.php";
break;
case 'puf':
$page = "puf.php";
break;
case 'sl':
$page = "sl.php";
break;
case 'sun':
$page = "sun.php";
break;
case 'tbp':
$page = "tbp.php";
break;
case 'thc':
$page = "thc.php";
break;
case 'tny':
$page = "tny.php";
break;
case 'vgw':
$page = "vgw.php";
break;
case 'vp':
$page = "vp.php";
break;
case 'vrt':
$page = "vrt.php";
break;
default:
$page = "csegainers.php";
break;
}
include($page);
}
?>
You write there in your if-condition:
if(isset($_GET['page']) && $_GET['page']!="")
So that means: If nothing is entered, don't go through the switch statement at all.
Either add an else-branch here or remove that if-clause.
This is not your question answer but is improved:
$allowed = array('fft','ghg','glh','ian','imh',
'in','lag','lib','lxx','mdm','mj',
'mmj','nf','puf','sl','sun','tbp',
'thc','tny','vgw','vp','vrt','crz' , //...
);
$page = 'csegainers';
if(isset($_GET['page']) && in_array($_GET['page'],$allowed)){
$page = $_GET['page'];
}
include($page . '.php');
The initial if won't let any blank $_GET['page'] pass by it. If you manually access a diferent value, say "document.php?page=example" the default case will fire normally.
Before I save my model, I would like to check if $ CONT_CEDULA meets the requirements. If not, then don't save. But when saving, it is as if the variable $ CONT_CEDULA hasn't got any data. I want to know if I'm doing well or need some other event or function. Also, the echo outputs no data.
beforeSave method
public function beforeSave() {
echo $this->$CONT_CEDULA;
switch (strlen($this->$CONT_CEDULA)) {
case 10:
return validarCI($this->$CONT_CEDULA);
break;
case 13:
return validarRUC($this->$CONT_CEDULA);
break;
default:
echo "Numero de caracteres invalidos" ;
return FALSE;
}
SpmContacto model
<?php
class SpmContacto extends \Phalcon\Mvc\Model {
public $CONT_CODIGO;
public $CONT_CEDULA;
public $CONT_RUCIDE;
public $CONT_NOMBRE;
public $CON_ESTADO;
public $CONT_TELEFO;
public $CONT_DIRECC;
public $CONT_AREA;
public $CONT_CARGO;
public $CONT_TIPOXX;
public $CONT_EMAIL;
public $CONT_USUARIO;
public $CONT_CLAVE;
public $CONT_CLAVEE;
public $CONT_FECNACI;
public $CONT_FECINSC;
public $CONT_TIPOCODIGO;
/**
* Initialize method for model.
*/
public function initialize() {
$this->setSchema("SPOLS");
$this->hasMany('CONT_CODIGO', 'SPMREFERENCIA', 'CONT_CODIGO', array('alias' => 'SPMREFERENCIA'));
$this->hasMany('CONT_CODIGO', 'SPTDETALLE', 'CONT_CODIGO', array('alias' => 'SPTDETALLE'));
$this->hasMany('CONT_CODIGO', 'SPTENCABEZADO', 'CONT_CODIGO', array('alias' => 'SPTENCABEZADO'));
}
function validarCI($strCedula) {
$suma = 0;
$strOriginal = $strCedula;
$intProvincia = substr($strCedula, 0, 2);
$intTercero = $strCedula[2];
$intUltimo = $strCedula[9];
if (!settype($strCedula, "float"))
return FALSE;
if ((int) $intProvincia < 1 || (int) $intProvincia > 23)
return FALSE;
if ((int) $intTercero == 7 || (int) $intTercero == 8)
return FALSE;
for ($indice = 0; $indice < 9; $indice++) {
//echo $strOriginal[$indice],'</br>';
switch ($indice) {
case 0:
case 2:
case 4:
case 6:
case 8:
$arrProducto[$indice] = $strOriginal[$indice] * 2;
if ($arrProducto[$indice] >= 10)
$arrProducto[$indice] -= 9;
//echo $arrProducto[$indice],'</br>';
break;
case 1:
case 3:
case 5:
case 7:
$arrProducto[$indice] = $strOriginal[$indice] * 1;
if ($arrProducto[$indice] >= 10)
$arrProducto[$indice] -= 9;
//echo $arrProducto[$indice],'</br>';
break;
}
}
foreach ($arrProducto as $indice => $producto)
$suma += $producto;
$residuo = $suma % 10;
$intVerificador = $residuo == 0 ? 0 : 10 - $residuo;
return ($intVerificador == $intUltimo ? TRUE : FALSE);
}
function validarRUC($strRUC) {
if (strlen($strRUC) != 13)
return FALSE;
$suma = 0;
$strOriginal = $strRUC;
$intProvincia = substr($strRUC, 0, 2);
$intTercero = $strRUC[2];
if (!settype($strRUC, "float"))
return FALSE;
if ((int) $intProvincia < 1 || (int) $intProvincia > 23)
return FALSE;
if ((int) $intTercero != 6 && (int) $intTercero != 9) {
if (substr($strRUC, 10, 3) == '001')
return validarCI(substr($strRUC, 0, 10));
return FALSE;
}
if ((int) $intTercero == 6) {
$intUltimo = $strOriginal[8];
for ($indice = 0; $indice < 9; $indice++) {
//echo $strOriginal[$indice],'</br>';
switch ($indice) {
case 0:
$arrProducto[$indice] = $strOriginal[$indice] * 3;
break;
case 1:
$arrProducto[$indice] = $strOriginal[$indice] * 2;
break;
case 2:
$arrProducto[$indice] = $strOriginal[$indice] * 7;
break;
case 3:
$arrProducto[$indice] = $strOriginal[$indice] * 6;
break;
case 4:
$arrProducto[$indice] = $strOriginal[$indice] * 5;
break;
case 5:
$arrProducto[$indice] = $strOriginal[$indice] * 4;
break;
case 6:
$arrProducto[$indice] = $strOriginal[$indice] * 3;
break;
case 7:
$arrProducto[$indice] = $strOriginal[$indice] * 2;
break;
case 8:
$arrProducto[$indice] = 0;
break;
}
}
} else {
$intUltimo = $strOriginal[9];
for ($indice = 0; $indice < 9; $indice++) {
//echo $strOriginal[$indice],'</br>';
switch ($indice) {
case 0:
$arrProducto[$indice] = $strOriginal[$indice] * 4;
break;
case 1:
$arrProducto[$indice] = $strOriginal[$indice] * 3;
break;
case 2:
$arrProducto[$indice] = $strOriginal[$indice] * 2;
break;
case 3:
$arrProducto[$indice] = $strOriginal[$indice] * 7;
break;
case 4:
$arrProducto[$indice] = $strOriginal[$indice] * 6;
break;
case 5:
$arrProducto[$indice] = $strOriginal[$indice] * 5;
break;
case 6:
$arrProducto[$indice] = $strOriginal[$indice] * 4;
break;
case 7:
$arrProducto[$indice] = $strOriginal[$indice] * 3;
break;
case 8:
$arrProducto[$indice] = $strOriginal[$indice] * 2;
break;
}
}
}
foreach ($arrProducto as $indice => $producto)
$suma += $producto;
$residuo = $suma % 11;
$intVerificador = $residuo == 0 ? 0 : 11 - $residuo;
//echo "$intVerificador == $intUltimo";
return ($intVerificador == $intUltimo ? TRUE : FALSE);
}
function validarID($strId) {
switch (strlen($strId)) {
case 10:
return validarCI($strId);
break;
case 13:
return validarRUC($strId);
break;
default:
return FALSE;
}
}
public function beforeSave() {
echo $this->$CONT_CEDULA;
switch (strlen($this->$CONT_CEDULA)) {
case 10:
return validarCI($this->$CONT_CEDULA);
break;
case 13:
return validarRUC($this->$CONT_CEDULA);
break;
default:
echo "Numero de caracteres invalidos";
return FALSE;
}
//echo $op;
}
public function getSource() {
return 'SPM_CONTACTO';
}
public static function find($parameters = null) {
return parent::find($parameters);
}
public static function findFirst($parameters = null) {
return parent::findFirst($parameters);
}
By default Phalcon wont output any data you "echo" in your controllers or your models. The easy 'workaround' is to die('your output');
If you return a value in a switch, it is unnecessary to add a break; to the end of your case.
public function beforeSave()
{
// check the content of $this->$CONT_CEDULA
var_dump($this->$CONT_CEDULA);
die;
switch (strlen($this->$CONT_CEDULA)) {
case 10:
return validarCI($this->$CONT_CEDULA);
case 13:
return validarRUC($this->$CONT_CEDULA);
default:
// an example to test if your code enters this case.
die("Numero de caracteres invalidos");
return FALSE;
}
}
I am having a small problem with my PHP MySQL Select. The function is inside of a PHP class. Here is the error I get:
Warning: mysql_fetch_array() expects parameter 1 to be resource,
integer given in C:\xampp\htdocs\include\database.php on line 59
Warning: extract() expects parameter 1 to be array, null given in
C:\xampp\htdocs\include\database.php on line 59
The function just simply updates the database to show what browser and OS they visited the site with. The function is called from another file that is called by an AJAX call that uses POST to send the data about the OS and browser that was gathered from a Javascript file. It only fails if there is an entry of the IP address already in the database. If there is no IP Address entry in the database it succeeds in creating one.
Here is my code:
function addStat($browser, $os){
$IE = 0; $Firefox = 0; $Safari = 0; $Opera = 0; $Chrome = 0; $otherb = 0;
$Windows = 0; $Linux = 0; $Mac = 0; $Android = 0; $iOS = 0; $otheros = 0;
$ql = 0; $totalVisits = 0;
$ip = ip2long($_SERVER['REMOTE_ADDR']);
$q1 = mysql_query("SELECT * FROM " . DB_STATS . " WHERE ip='$ip'", $this->connection);
if (mysql_num_rows($q1)==0){
$browser = mysql_real_escape_string($browser);
$os = mysql_real_escape_string($os);
switch($browser){
case "Internet Explorer":
$IE += 1;
break;
case "Firefox":
$Firefox += 1;
break;
case "Safari":
$Safari += 1;
break;
case "Opera":
$Opera += 1;
break;
case "Chrome":
$Chrome += 1;
break;
default:
$otherb += 1;
break;
}
switch($os){
case "Windows":
$Windows += 1;
break;
case "Mac OS X":
$Mac += 1;
break;
case "Linux":
$Linux += 1;
break;
case "Android":
$Android += 1;
break;
case "iOS":
$iOS += 1;
break;
default:
$otheros += 1;
break;
}
$q = $this->query("INSERT INTO " . DB_STATS . " VALUES (null, '$ip', '$Chrome', '$IE', '$Firefox', '$Opera', '$Safari', '$otherb', '$Windows', '$Mac', '$Linux', '$Android' , '$iOS' , '$otheros', 1)");
if ($q == true){
return(1);
}
else{
return(0);
}
}
else if (mysql_num_rows($q1)==1){
extract(mysql_fetch_array($ql));
switch($browser){
case "Internet Explorer":
$IE += 1;
break;
case "Firefox":
$Firefox += 1;
break;
case "Safari":
$Safari += 1;
break;
case "Opera":
$Opera += 1;
break;
case "Chrome":
$Chrome += 1;
break;
default:
$otherb += 1;
break;
}
switch($os){
case "Windows":
$Windows += 1;
break;
case "Mac OS X":
$Mac += 1;
break;
case "Linux":
$Linux += 1;
break;
case "Android":
$Android += 1;
break;
case "iOS":
$iOS += 1;
break;
default:
$otheros += 1;
break;
}
$totalVisits += 1;
$q = $this->query("UPDATE " . DB_STATS . " set Chrome='$Chrome', IE='$IE', Firefox='$Firefox', Opera='$Opera', Safari='$Safari', otherb='$otherb', Windows='$Windows', Mac='$Mac', Linux='$Linux', Android='$Android' , iOS='$iOS' , otheros='$otheros', totalVisits='$totalVisits'");
if ($q == true){
return(1);
}
else{
return(0);
}
}
else{
return(-1);
}
}
I hope everything made sense and that someone will help.
I see it now -- you used $ql (lower case L) when you intend to use $q1. Let this be a lesson against using very short variable names or very similar names.
// $ql was initialized to 0
$ql = 0; $totalVisits = 0;
// $q1 holds the result resource
extract(mysql_fetch_array($q1));
It is not advisable to call extract() on the output of mysql_fetch_array() unless you also specify the second parameter MYSQL_ASSOC as the fetch type. By default it returns both numeric and associative indices for each column.
extract(mysql_fetch_array($q1, MYSQL_ASSOC));
// Or better
extract(mysql_fetch_assoc($q1));
In general, I would probably advise against using extract() in most any situation, since it results in numerous variables dumped into the global namespace, in particular when you have done SELECT * without being specific about which columns are selected. Better to access them via their array:
$row = mysql_fetch_assoc($q1);
echo $row['browser'];